Reputation: 1499
I have the following M2M relationship between OrderPage
and Site
. How can I filter Site
which belong to all OrderPage
? Something like:
Site.objects.filter(all of the orderpage).distinct()
My model is
class OrderPage(models.Model):
description = models.CharField(max_length=255, blank=False)
sites = models.ManyToManyField(Site)
Upvotes: 0
Views: 109
Reputation: 59445
The easiest way is to fetch all Site
instances except those which don't have any OrderPage
s associated. For example:
Site.objects.all().exclude(orderpage__isnull=True)
Upvotes: 1