Reputation: 3076
I need to filter objects of model class. I want to query all objects where 'date' field is in some range and one of other 2 fields are True (one or both).
Following code doesn't appear tobe working:
visits = Visit.objects.filter(date__range=(now, delta), Q(sms_reminder=True) | Q(email_reminder=True))
any suggestions?
Upvotes: 0
Views: 122
Reputation: 9346
Swap the order of your filters:
visits = Visit.objects.filter(
Q(sms_reminder=True) | Q(email_reminder=True),
date__range=(now, delta),
)
From the Q
docs:
However, if a Q object is provided, it must precede the definition of any keyword arguments.
Standard python: args then kwargs. (Caught me out a few times)
Upvotes: 1
Reputation: 227
If your filter is (A OR B) AND C
You can try with this filter :
visits = Visit.objects.filter( (Q(sms_reminder=True)|Q(email_reminder=True)) & Q(date__range=(now, delta)))
Upvotes: 0