I usually do

def __unicode__(self):
       return "%d" % self.question_number


On Fri, Jan 9, 2009 at 2:42 PM, Eric Abrahamsen <gir...@gmail.com> wrote:

>
>
> On Jan 9, 2009, at 10:19 PM, _Sebastian_ wrote:
>
> >
> > Hi all,
> >
> > I've been following the tutorial
> http://docs.djangoproject.com/en/dev/intro/tutorial01/#playing-with-the-api
> > and working on a own test-project as well.
> >
> > so I tried to adapt from
> >
> > class Poll(models.Model):
> >    question = models.CharField('question',max_length=200)
> >
> >    def __unicode__(self):
> >        return self.question
> >
> > to this
> >
> > class Poll2(models.Model):
> >    question_number = models.IntegerField()
> >
> >    def __unicode__(self):
> >        return self.question_number
> >
> > to list the actual question number instead of Question Object in the
> > admin interface.
> >
> > Somehow it was not working. How do I need to do it so it's right?
>
> A couple of questions: what do you mean exactly by question number?
> And also, how is it not working? And, for good measure, what would it
> look like if it were right? As you've written this, it should work
> fine – when you create a Poll object its data will consist of a number
> (but no question!), and that number will be returned by the
> __unicode__ method. You might be trying to retrieve the primary key
> for Poll2 objects, which is a column that Django usually makes
> implicitly for you, in the background, unless you specify that you
> want to do it yourself. If this is the number you want, you can get it
> in the __unicode__ method as self.pk. That might not really be what
> you want, though, because that number will increment regardless of
> deletes or modifications, and you can't (or shouldn't) modify it
> manually. If you were hoping for a number attribute that you can
> modify, and use for ordering, etc., let us know, and that should be
> easy to arrange.
>
> Welcome and good luck,
> Eric
>
>
> > cheers,
> >
> > seb
> >
> > >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to