Reputation: 1689
What query can I use to return all the Organisation objects that are members of a certain membership_id
value?
e.g. return all Organisation objects that have a membership_id = 101
class Organisations(model)
id = models.CharField()
memberships = models.ManyToManyField("self", through="Memberships")
class Memberships(model)
membership_id = models.IntegerField()
organisation_id = models.ForeignKey(Organisations, related_name="orgs",)
Upvotes: 1
Views: 51
Reputation: 4171
Try this:
Organisations.objects.filter(orgs__membership_id=101)
Upvotes: 1