[Django]-Modeling three-way relationship in SQL/Django ORM

4👍

You can use a custom through model to save extra data for a single relationship:

class Person(models.Model):
    organisations = models.ManyToManyField(Organisation, through='Position')

class Position(models.Model):
    person = models.ForeignKey(Person)
    organisation = models.ForeignKey(Organisation)
    title = models.CharField(max_length=50)

Also check the documentation on through models.

👤knbk

Leave a comment