# Filtering Objects (Query Sets)

**URL:** https://forum.codewithmosh.com/t/filtering-objects-query-sets/15592
**Category:** Django
**Created:** [October 2, 2022, 7:34pm UTC](https://forum.codewithmosh.com/t/filtering-objects-query-sets/15592 "2022-10-02T19:34:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![codepls](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@codepls](https://forum.codewithmosh.com/u/codepls)
#### Post date: [October 2, 2022, 7:34pm UTC](https://forum.codewithmosh.com/t/filtering-objects-query-sets/15592/1 "2022-10-02T19:34:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tooTALLtim](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/tootalltim/32/5469_2.png) [@tooTALLtim](https://forum.codewithmosh.com/u/tooTALLtim)
#### Post date: [January 22, 2023, 5:53pm UTC](https://forum.codewithmosh.com/t/filtering-objects-query-sets/15592/2 "2023-01-22T17:53:09Z")

</div>

I was confused too! I looked around but couldn’t find a good answer. But I looked at the SQL queries in the debug toolbar, and found that if I had a single or double underscore between ‘collection’ and ‘id’ as so:

`query_set = OrderItem.objects.filter(product__collection_id=3)`

or

`query_set = OrderItem.objects.filter(product __collection__ id=3)`

my SQL queries were identical!

![Screenshot from 2023-01-22 10-46-40](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/9/9c70ff783d88dd3fa441c7e6419ecef5af9be0dc.png)

The confusion deepens 😛
