Why use "through" argument for ManyToManyField in Django models?
Looking through the Django docs and trying to figure out the use of the "through" argument. Here is a link to the [doc][1].

The example:

    class Person(models.Model):
        name = models.CharField(max_length=128)

        def __unicode__(self):
            return self.name

    class Group(models.Model):
        name = models.CharField(max_length=128)
        members = models.ManyToManyField(Person, through='Membership')

        def __unicode__(self):
            return self.name

    class Membership(models.Model):
        person = models.ForeignKey(Person)
        group = models.ForeignKey(Group)
        date_joined = models.DateField()
        invite_reason = models.CharField(max_length=64)

Why is the "members" attribute of Group even needed? Isn't the 'group' ForeignKey of Membership enough to follow the relation and access that information?


  [1]: https://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-on-many-to-many-relationships
Why use "through" argument for ManyToManyField in Django models?
===

Looking through the Django docs and trying to figure out the use of the "through" argument. Here is a link to the [doc][1].

The example:

    class Person(models.Model):
        name = models.CharField(max_length=128)

        def __unicode__(self):
            return self.name

    class Group(models.Model):
        name = models.CharField(max_length=128)
        members = models.ManyToManyField(Person, through='Membership')

        def __unicode__(self):
            return self.name

    class Membership(models.Model):
        person = models.ForeignKey(Person)
        group = models.ForeignKey(Group)
        date_joined = models.DateField()
        invite_reason = models.CharField(max_length=64)

Why is the "members" attribute of Group even needed? Isn't the 'group' ForeignKey of Membership enough to follow the relation and access that information?


  [1]: https://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-on-many-to-many-relationships