user3517806
user3517806

Reputation: 33

ManyToMany field, check if relation exists

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

views:

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

How to check if a.item is in ManyToMany relation with b.box?

Upvotes: 3

Views: 4450

Answers (1)

Eugene Soldatov
Eugene Soldatov

Reputation: 10135

It's pretty simple:

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

Upvotes: 3

Related Questions