So if I have a Person object "ringo" and I want to get info about the Groups he is a member of, I would do this:
for group in ringo.group_set.all() print( group.name ) My question is, how do I print the "date_joined" without having to do this: for group in ringo.group_set.all() print( Membership.objects.get(person=ringo, group=group).date_joined ) That seems very DB inefficient. Nate On Sep 19, 9:43 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > On Sat, Sep 20, 2008 at 8:37 AM, Nate Thelen <[EMAIL PROTECTED]> wrote: > > > Looking at the docs here: > > >http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o... > > > I cannot find any reference to how to access the data in the > > "Membership" table. For example, if I have a reference to the > > "beatles" object, how do I find the "date_joined" for each of the > > "Person" objects. I have looked through the other sections of the > > documentation, searched this group, and searched via Google, but > > couldn't find the info. > > Short version: You access the membership table using the foreign key > relationship that the membership defines. > > Long version: Your question ("the date_joined for each person object") > is actually ill posed - a person doesn't have a date_joined without a > group to also give context. "The date person X joined group Y" can be > answered as: > > >>> Membership.objects.get(person=X, group=y).date_joined > > It might help to think about it like this - m2m-intermediate tables > don't add extra data to an m2m relation, they make a 2-step foreign > key relation behave like an m2m relation. > > Yours, > Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---