Closed emilian closed 11 years ago
Here's what I did:
def _get_filtered_customers(request, customer_filters): """ """
customers = Customer.objects.all()
customer_ordering = request.session.get("customer-ordering", "id")
customer_ordering_order = request.session.get("customer-ordering-order", "")
name = customer_filters.get("name", "")
if name != "":
f = Q(user__last_name__icontains=name)
f |= Q(user__first_name__icontains=name)
customers = customers.filter(f)
# Ordering
customers = customers.order_by("%s%s" % (customer_ordering_order, customer_ordering))
return customers
Works for me
Not sure why Github mangled my code... First comment I have submitted here...
The only issue with that code is that the Customer model does not require a User object. In that case it will probably throw an error if the customer does not have a User object linked to the customer.
rjacks solution seems to be OK. It will work even for null user objects
It looks like filtering customers is broken. The master branch shows that the filter code was commented out in lfs/manage/views/customers.py file on line ~350:
The issue here is that you cannot filter based on the sa_object_id.
My solution is to store the first and last name values in the Customer model in addition to storing that information in the generic address model. The first and last name values in the address should only be used when printing the invoice / packing slip because it is possible that the recipient has a different name than the customer account (for example, when sending a gift to a different person).
What are your thoughts on this solution?