Thanks! I think I understand it now! Mark
On Wed, May 23, 2012 at 8:00 AM, Simone Federici <s.feder...@gmail.com>wrote: > On Wed, May 23, 2012 at 4:40 PM, Mark Phillips <m...@phillipsmarketing.biz > > wrote: > >> Now, can you please explain why it worked? What does the related_name do >> and why do I need it? > > When you define a ForeignKey, django creates dinamically a reverse > relationship. > > take this example: > A > B.a -> A > > > from an instance of b = B() > you can arrive to the related instance of A by b.a > > but you can also from the instance of a = A() > retrieve all instace related of B by a.b_set() > > but if in a model there are two or more relationship versus the same model > the names clashed! and Django ask you to give their names by related_name > property. > > in your code: > > t = Team() > > this give you all games where the team was the home team > t.homegame_set.all() > > this give you all games where the team was the visitor team > t.vititorgame_set.all() > > > by default > t.game_set clash! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.