ManyToMany字段,检查是否存在关系

时间:2014-04-14 11:37:56

标签: django

class Player(models.Model):
    item = models.ForeignKey(Test)
    box = models.ManyToManyField(Test)

的观点:

a = Player.object.get(id=1)
b = Player.objects.get(id=5)

如何检查a.item是否与b.box处于ManyToMany关系?

1 个答案:

答案 0 :(得分:3)

非常简单:

Playes.objects.filter(pk=a.pk, box__pk=b.pk).exists()