Friday, August 30, 2013

A quick Question about ManyRelatedManager.

I'm new to django and my question may be immature, but I really need answer to it.

I have a model in my application as following.

class BacklogEntry(models.Model):

    PRIORITY_CHOICES = dict([(0, 'NA'), (1, 'Low'), (2, 'Medium'), (3, 'High'), (4, 'Very High'), (5, 'Apocalypse')])
    STATUS_CHOICES = dict([(0, 'No Longer Valid'), (1, 'Suspended'), (2, 'In Progress'), (3, 'Almost Finished'), (4, 'Finishded')])

    description = TextField()
    start_time = DateTimeField()
    end_time = DateTimeField()
    users = ManyToManyField(User)
    status = IntegerField(choices=STATUS_CHOICES.items())
    priority=IntegerField(choices=PRIORITY_CHOICES.items())

    backlog = ForeignKey(Backlog)

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.

Some help is required.

--
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+unsubscribe@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.

No comments:

Post a Comment