[Answer]-Django Querying By a Set Relationship (Reverse)

1đź‘Ť

âś…

Without knowing how your model looks like:

Toy.objects.filter(type__in=["Dog", "Cat"])

or

Toy.objects.filter(type__in=["Strawberry", "Banana"])

and thirdly (with all Toy types that is a fruit or an animal)

Toy.objects.filter(type__in=["Dog", "Cat", "Strawberry", "Banana"])

Since you don’t store “animal” as a type according to what you’ve described you have no need for {'Animal':[...], 'Fruit':[...]}.

Leave a comment