Sorry for the none-descriptive title, but I didn’t really have a clue as to how to word this.
Say I have two models as such:
class Person(...):
name = ... #have an attribute
class Family(...):
mum = models.OneToOneField(Person)
dad = models.OneToOneField(Person)
When I have a family containing mum and dad, I would think calling dad.family would yield me the family dad is in. However, I get an error message saying that this clashes with the mum attribute. The solution here is to use relative_names. But calling the family from mums side something else than from dads feels weird for me. WHy can’t I just call dad.family? Could someone explain to me what exactly is clashing here?
Thanks!
The problem is that, given your model, a
Personcould be amumto one Family, and adadto a different family.In that case, a query like this would be ambiguous:
For that reason, you need to define a reverse relation name for each one (family_as_mum and family_as_dad, for instance)