Something like this should work:
model.objects.filter(Q(is_paid=False) | Q(status='toship', otherfield='FOO', anotherfield='BAR'))
Edit: You cannot create a query dynamically in the same way as you can build a string containing an SQL statement that will be executed upon completion. If you want to do this, I would suggest using an if state, a function, or what works best for your use:
if query == 'simple': result = model.objects.filter(Q(is_paid=False)) else: result = model.objects.filter(Q(is_paid=False) | Q(status='toship', otherfield='FOO', anotherfield='BAR')) for items in result: ...
It may be more complicated, but I'm sure you understand.
source share