Reputation: 10252
I have these 4 tables in Django:
A Store has many products, a product has many orders and an order has one product and one customer.
How would I query in Django to retrieve the distinct list of customers per store? I could easily do it with an SQL query but I would really prefer to go the ORM way.
Upvotes: 5
Views: 2995
Reputation: 31250
If you have a Store already fetched:
customers = Customer.objects.filter(order__product__store=store)
Upvotes: 7