The way I think of the value of the "through" table approach is when you want to attach information to the relationship that does not belong on either model.
I like a band/musician example. A person can be a part of many bands A band has many people so here we have a classic M2M But a person is part of a band as a "member" so you would create a "member" through table that would hold things like: instruments_played start_date end_date These are things about that person in that band that don't belong on the person or band object. You might have relationships from this member table to other objects like songs etc -Preston On Oct 22, 7:57 am, Monika Sulik <[email protected]> wrote: > Hi, > > I was wondering what exactly are the advantages of having code like > this: > > > > class Foo (models.Model): > bar_m2m = models.ManyToManyField(Bar,through='Foo_Bar') > > class Bar (models.Model): > pass > > class Foo_Bar (models.Model): > foo = models.ForeignKey(Foo) > bar = models.ForeignKey(Bar) > x = models.IntegerField() > > > > over having the same code, but having the Foo class like so: > > > > class Foo (models.Model): > pass > > > > In both cases I can use foo.foo_bar_set and bar.foo_bar_set (assuming > foo is a Foo Object and bar is a Bar Object). Why would I need the > bar_m2m variable? > I'm probably missing something pretty obvious, but if someone could > point out the answer to me that would be great :) > > Monika --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

