自分と関係のあるモデルが欲しいのですが、ManyToMany
どうやって書くのかわかりませんが、やりたいことを説明するコードを書いてみます。
class Person(models.Model):
name = models.CharField()
occupation = models.CharField()
friends = models.ManyToManyField('self', through = PersonFriends)
友達に見てもらいたいモデル
class PersonFriends(models.Model)
???
comment = models.CharField()
たとえば、他のモデルの名前が「Pet」の場合、through関係のあるManyToMany
フィールドでは、そのフィールドにthrough classという名前を付けて、モデルにします。そして例えばperson
pet
ForeignKey(Person)
Pet
同じモデルになった2人のフィールドのモデルで、fields
自分の名前を何に付けますか?PersonFriends