Categories
Python Answers

How to filter a Python Django query with a list of values?

Spread the love

To filter a Python Django query with a list of values, we can use the filter method with in.

For instance, we write

Blog.objects.filter(pk__in=[1, 4, 7])

to search Blog entries with pk set to 1,4 or 7 by calling Blog.objects.filter with the pk_in argument set to [1, 4, 7].

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *