Reputation: 88598
I have two querysetd in Django. How can I efficiently check whether they have any elements in common, i.e. if there exists any element that is in both querysets?
Upvotes: 3
Views: 1705
Reputation: 6355
You can use query sets like sets:
intersection = queryset1 & queryset2
intersection
will be the intersection of the two querysets
Upvotes: 1
Reputation: 79645
You could check if an intersection exists:
(qs1 & qs2).exists()
Upvotes: 5