[Answered ]-QuerySet filter with multiple ManyToMany field lookups does not behave as expected

1👍

Have a look at https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships (the second note in particular). You’ll see exclude behaves slightly differently to filter when applying criteria to ‘each’ in a m2m set rather than ‘any’.

The way round provided on that page, fitted to your case, would look something like:

User.objects.exclude(
    vacation__in = Vacation.objects.filter(
         start__lte=now, 
         end__gt=now
    ),
)

Leave a comment