On Aug 30, 10:54 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Sorry but I didnt get it :( > (Perhaps you should actually call the field user rather than user) . > Could you please explain more ?
Sorry, that should have been "you should call the field users" - i.e. plural, because it refers to more than one user. > I tried to do following but couldnt get user information, > > In [36]: p = PU.objects.all() > > In [37]: p > Out[37]: [<PU: jwang>, <PU: admin>] > > In [38]: for i in p: > ....: i.user.id > ....: > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call > last) > > D:\PMO\<ipython console> in <module>() > > AttributeError: 'ManyRelatedManager' object has no attribute 'id' Each 'i' has MULTIPLE users. So you can't say i.user.id, because 'user' refers to MANY users. You'll need a nested loop: for i in p: for a_user in i.user.all(): print a_user.id To be honest, all this is in the documentation. Django has some of the best docs out there for any open-source project, and the question you're asking is absolutely basic. See here, for example: http://www.djangoproject.com/documentation/db-api/#many-to-many-relationships -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---