1👍
✅
The problem is that your storage_list
translates into a list. The .item_set.all()
methods are only valid on the actual objects in the list.
Basic rule that I try to use: ask for what you want. In your case, you really want to have the items, not the storage objects. So something like this:
Item.objects.filter(storage__user__id=user_id)
So: items which are connected with a user through a storage object. Django will translate that into the proper SQL joins for you.
Note that you don’t need to do the __id
for user. You can omit that part as django by default will look at the primary key. So:
Item.objects.filter(storage__user=user_id)
Source:stackexchange.com