How to filter results that are not part of a ManyToManyField?

22 views
Skip to first unread message

Neto

unread,
Oct 3, 2014, 3:49:25 PM10/3/14
to django...@googlegroups.com
Hello,

I have it model:

class People(models.Model):
    children = models.ManyToManyField('self', blank=True, null=True)

I want to filter the first of each family tree. *Knowing that children can have children

How I do it?

People.objects.filter(????)

Collin Anderson

unread,
Oct 3, 2014, 9:24:51 PM10/3/14
to django...@googlegroups.com
This may look totally crazy, but does this do what you want?
People.objects.filter(people=None)

It may make more sense to do this:
class Person(models.Model):
    children
= models.ManyToManyField('self', blank=True, related_name='parents')
Person.objects.filter(parents=None)


Reply all
Reply to author
Forward
0 new messages