Author: julien Date: 2011-09-11 12:28:18 -0700 (Sun, 11 Sep 2011) New Revision: 16817
Modified: django/trunk/docs/topics/db/models.txt django/trunk/docs/topics/db/queries.txt Log: Fixed #16742 -- Provided code examples in the models documentation for accessing extra fields on many-to-many relationships. Many thanks to aj for the suggestion and to Nick Lang for the patch. Modified: django/trunk/docs/topics/db/models.txt =================================================================== --- django/trunk/docs/topics/db/models.txt 2011-09-11 05:58:34 UTC (rev 16816) +++ django/trunk/docs/topics/db/models.txt 2011-09-11 19:28:18 UTC (rev 16817) @@ -325,7 +325,7 @@ For details on accessing backwards-related objects, see the `Following relationships backward example`_. - + For sample code, see the `Many-to-one relationship model tests`_. .. _Following relationships backward example: http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects @@ -519,7 +519,26 @@ ... membership__date_joined__gt=date(1961,1,1)) [<Person: Ringo Starr] +If you need to access a membership's information you may do so by directly +querying the ``Membership`` model:: + >>> ringos_membership = Membership.objects.get(group=beatles, person=ringo) + >>> ringos_membership.date_joined + datetime.date(1962, 8, 16) + >>> ringos_membership.invite_reason + u'Needed a new drummer.' + +Another way to access the same information is by querying the +:ref:`many-to-many reverse relationship<m2m-reverse-relationships>` from a +``Person`` object:: + + >>> ringos_membership = ringo.membership_set.get(group=beatles) + >>> ringos_membership.date_joined + datetime.date(1962, 8, 16) + >>> ringos_membership.invite_reason + u'Needed a new drummer.' + + One-to-one relationships ~~~~~~~~~~~~~~~~~~~~~~~~ Modified: django/trunk/docs/topics/db/queries.txt =================================================================== --- django/trunk/docs/topics/db/queries.txt 2011-09-11 05:58:34 UTC (rev 16816) +++ django/trunk/docs/topics/db/queries.txt 2011-09-11 19:28:18 UTC (rev 16817) @@ -1036,6 +1036,8 @@ the database. Every addition, creation and deletion is immediately and automatically saved to the database. +.. _m2m-reverse-relationships: + Many-to-many relationships -------------------------- -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.