[Answered ]-Dynamic creating an "OR" Query in django

2👍

Use the in field lookup:

ids = range(1,21)
specific_customers = Customer.objects.filter(pk__in=ids) 

Alternatively, if the use of range() is not just an example, and this really will always be a range of numbers you should use range lookup instead:

specific_customers = Customer.objects.filter(pk__range=(1, 21)) 

Both examples are equivalent to your original code.

Leave a comment