Django's ManyToMany Relationship with Additional Fields Django's ManyToMany Relationship with Additional Fields django django

Django's ManyToMany Relationship with Additional Fields


Here is example of what you want to achieve:

http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

In case link ever breaks:

from django.db import modelsclass Person(models.Model):    name = models.CharField(max_length=128)    def __str__(self):              # __unicode__ on Python 2        return self.nameclass Group(models.Model):    name = models.CharField(max_length=128)    members = models.ManyToManyField(Person, through='Membership')    def __str__(self):              # __unicode__ on Python 2        return self.nameclass Membership(models.Model):    person = models.ForeignKey(Person)    group = models.ForeignKey(Group)    date_joined = models.DateField()    invite_reason = models.CharField(max_length=64)