[Answer]-Django objects filter – AND with OR

1👍

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)

0👍

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)))
👤Naresh

Leave a comment