Django ManyToMany 查询交集
Django ManyToMany Query intersection
我有以下模型结构:
class Person(model.Models):
groups = models.ManyToManyField(Group)
class Group(model.Models):
pass
class Event(model.Models):
groups = models.ManyToManyField(Group)
我现在想要做的是获取包含特定 Person
所在的 Group
的所有 Event
。我该怎么做?
这应该有效:
Event.objects.filter(groups__person=person)
我有以下模型结构:
class Person(model.Models):
groups = models.ManyToManyField(Group)
class Group(model.Models):
pass
class Event(model.Models):
groups = models.ManyToManyField(Group)
我现在想要做的是获取包含特定 Person
所在的 Group
的所有 Event
。我该怎么做?
这应该有效:
Event.objects.filter(groups__person=person)