From an example you can see a multiple OR query filter:
Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
For example, this results in:
[<Article: Hello>, <Article: Goodbye>, <Article: Hello and goodbye>]
However, I want to create this query filter from a list. How to do that?
e.g. [1, 2, 3] -> Article.objects.filter(Q(pk=1) | Q(pk=2) | Q(pk=3))
To build more complex queries there is also the option to use built in Q() object's constants Q.OR and Q.AND together with the add() method like so:
This one is for dynamic pk list:
See the docs:
Note that this method only works for primary key lookups, but that seems to be what you're trying to do.
So what you want is:
You can use the |= operator to programmatically update a query using Q objects.
You could chain your queries as follows: