How do I write a Django model with ManyToMany relationsship with self through a Model

Viewed 7972

I want to have a model with a ManyToMany relationship with itself, I don't know how to write this but I'l try to write some code to illustrate what I want to do.

class Person(models.Model):
   name = models.CharField()
   occupation = models.CharField()

   friends = models.ManyToManyField('self', through = PersonFriends)

My Model that I want the friends to go through

class PersonFriends(models.Model)
   ???
   comment = models.CharField()

In a ManyToMany field with through relationship if the other model's name was "Pet" for example I'd name my fields in that through class person and pet and make them models. ForeignKey(Person) and Pet for example

What to I name my fields in my PersonFriends model for the two person-fields now that they are the same model?

4 Answers
Related