Querying django ManyToMany
问题 I have got Foo <=> FooGroup <=> Bar relation, where <=> stands for ManyToMany field. How do I retrieve all the Foo s for a specific Bar instance? 回答1: Here's an example with auth models, where the relationship is very much like your structure : User <=> Groups <=> Permission from django.contrib.auth import models models.Permission.objects.filter(group__user=models.User.objects.get(username="webmaster")) With your example: Foo.objects.filter(foogroup__bar=barinstance) 来源: https://stackoverflow