Django ManyToMany Query交集

时间:2015-04-16 16:14:32

标签: python django database many-to-many

我有以下模型结构:

class Person(model.Models):
    groups = models.ManyToManyField(Group)

class Group(model.Models):
    pass

class Event(model.Models):
    groups = models.ManyToManyField(Group)

我现在要做的是获取包含特定Event所在的Group的所有Person。我该怎么做?

1 个答案:

答案 0 :(得分:2)

这应该有效:

Event.objects.filter(groups__person=person)