On 30/08/2013 18:53, Abhishek Vaid wrote:
Now I want to define *__unicode__(self)* method, in which I'll be creating a string representation for the *BacklogEntry* object. In doing so, I need to access all *users *which are referenced by *ManyRelatedManager*. Basically, I want to access name attribute of each User, referenced in a foreign key manner. But I'm not sure how to do that.
Your users are available through the RelatedManager on your BacklogEntry object, this means that you can have access to users with `self.users`.
`self.users` is a manager, so to access all users in the relationship, use something like `self.users.all()`
def __unicode__(self): for user in self.users.all(): # do whatever you want with the `user` object username = user.username -- Laurent Meunier <laur...@deltalima.net> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.