Hello, I’m on Part1 of Mosh’s Django course and I have a question regarding query sets.
Order items for products in collection 3
Solution: queryset = OrderItem.objects.filter(product__collection__id=3)
My question:
- Can someone please help clarify how chaining product__collection works? Does Django know to look up collection from the ‘Collection’ model? I think I missed something somewhere but can’t seem to recall when it was mentioned. The OrderItem model does not have ‘collection’ in it - does this mean that it can do a reverse lookup to see if product has a foreign key on any field where collection exists?
- My understanding was that adding __ had to be followed with a value that was a field lookup option