Ticket #16742: access_extra_fields_on_through_model.diff
File access_extra_fields_on_through_model.diff, 1.1 KB (added by , 13 years ago) |
---|
-
docs/topics/db/models.txt
519 519 ... membership__date_joined__gt=date(1961,1,1)) 520 520 [<Person: Ringo Starr] 521 521 522 If you were wanted to access any of the membership information from a Person 523 you would first have to query the Membership model and then you can access 524 the fields related to the membership:: 522 525 526 >>> ringos_membership = Membership.objects.get(group=beatles, person=ringo) 527 >>> ringos_membership.date_joined 528 datetime.date(1962, 8, 16) 529 >>> ringos_membership.invite_reason 530 u'Needed a new drummer.' 531 532 Another way to access the same fields would be to use the reverse lookup from 533 ``ringo``:: 534 535 >>> ringos_membership = ringo.membership_set.get(group=beatles) 536 >>> ringos_membership.date_joined 537 datetime.date(1962, 8, 16) 538 >>> ringos_membership.invite_reason 539 u'Needed a new drummer.' 540 541 523 542 One-to-one relationships 524 543 ~~~~~~~~~~~~~~~~~~~~~~~~ 525 544