Self referencing one to many Model

176 Views Asked by At

Say I have a person class like so:

class Person(models.Model):
  name = models.CharField(max_length=128)

However if I wanted to add a parents field that referenced multiple Person objects I run into some issues.

set as a ManyToMany it puts the 'child' as the parent of the intended parent in addition to adding the parent to the child when doing:

Person_child.parent.add(Person_parent)

but setting it as a ForeignKey will only allow me to set one parent.

How can I create a self referring relationship in Person so that I can add Moms, Dads, Step Parents, Adopted parents, etc without creating specific fields for them?

1

There are 1 best solutions below

0
On BEST ANSWER

The secret sauce was adding symetrical=False in a ManyToMany