I have two models and one admin model:
class Person(models.Model):
firstname = models.CharField(maxlength=50)
surname = models.CharField(maxlength=5
This code isn't complete - you've got two ForeignKeys from Friends
to Person
, so at least one of them will need a related_name
attribute to prevent clashes. The code simply won't run as it is.
If a Person can only be friends with one other person, you should use a OneToOneField
rather than a ForeignKey
. Then, you can simply refer to my_person.friend1.person1.surname
, where my_person
is the Person you starting with, and friend1
is the related_name
value I mentioned above.