[Django]-Checking whether two Django querysets have any items in common

5👍

You could check if an intersection exists:

(qs1 & qs2).exists()

2👍

In Django 1.11, simply queryset1.intersection(queryset2)

1👍

You can use query sets like sets:

intersection = queryset1 & queryset2

intersection will be the intersection of the two querysets

Leave a comment