43

I'd like to filter a Django queryset using an array as a constraint on a field. AKA, my array, for example, a set of primary keys. I want to get only the objects that would be in that array, like the query in SQL would be:

SELECT * from table where id in [1,3,4,5,6....];
1

1 Answer 1

75
.filter(id__in=[1, 3, 4, 5, 6....])

Read more about it at Django docs.

Sign up to request clarification or add additional context in comments.

1 Comment

And a link to the queryset docs should help with many followup questions docs.djangoproject.com/en/dev/ref/models/querysets/#in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.