How do I pass a list of Qs to filter for OR lookups? Something like:
q_list = [Q(xyz__isnull=True), Q(x__startswith='x')]?
Without a list I would do:
Model.objects.filter(Q(xyz__isnull=True) | Q(x__startswith='x'))
Use python's reduce() function:
import operator
reduced_q = reduce(operator.or_, q_list)
Model.objects.filter(reduced_q)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With