[Fixed]-Django: how to query all values in an array?

1👍

The __in operator is for filtering by a set. It is not meant for checking multiple values at once in a many-to-many relationship.

It literally translate to the following in SQL:

SELECT ... WHERE hobbies IN (1, 3, 4);

So you’d need to build your query using AND conditions. You can do this with consecutive filters:

queryset = Personne.objects.all()

# build up the queryset with multiple filters
for hobby in hobbies2:
    queryset = queryset.filter(hobbies2=hobby)
👤Soviut

Leave a comment