I been struggling with doing a query to get the rows where a Item only exsist in Parnet field and not Child field.
This is the models.
class Item(models.Model):
text = models.CharField()
class ItemRelations(models.Model):
child = models.ForeignKey('Item', related_name='itemchild')
parent = models.ForeignKey('Item', related_name='itemparent')
So I only want to filter out the Items that are not a child, but is a Parent. I call it the firstParent.
I tried so many different ways. I want to accomplish something like this.
firstParent = Item.objects.filter(ItemRelations_parent__is=self).exclude(ItemRelations_child__is=self)
Is it possible. Or does one have to make several queries and loops to manage this?