I have the following models:
class Parent(models.Model):
item_involved = models.ManyToManyField(Item, through=ItemInvolved)
class ItemInvolved(models.Model):
parent = models.ForeignKey(Parent, related_name='item_involvement')
item = models.ForeignKey(Item)
kind = models.PositiveIntegerField()
I want to retrieve all Parent
s for which an Item
has pk=20 and its ItemInvolved
has kind=10.
Edit:
Say I have the following objects:
Parent(pk=1)
Parent(pk=2)
Parent(pk=3)
ItemInvolved(pk=11, parent=1, item=18, kind=10)
ItemInvolved(pk=12, parent=1, item=19, kind=10)
ItemInvolved(pk=13, parent=1, item=20, kind=10)
ItemInvolved(pk=14, parent=2, item=20, kind=10)
ItemInvolved(pk=15, parent=3, item=19, kind=10)
ItemInvolved(pk=16, parent=3, item=20, kind=20)
I need a query that will yield:
[<Parent: 1>, <Parent: 2>]