How can I find the intersection of two Django querysets?

In most cases you can just write (exploiting the “Set” part of QuerySet) :

intersection = Model.objects.filter(...) & Model.objects.filter(...)

This isn’t very well documented, but should behave almost exactly like using AND conditions on conditions from both queries. Relevant code: https://github.com/django/django/blob/1.8c1/django/db/models/query.py#L203

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)