Problem with object values in Django 1.0

2 views
Skip to first unread message

Opel

unread,
Oct 31, 2008, 10:28:48 AM10/31/08
to Django developers
I have been following along to the Django Tutorial after downloading
and installing V1.0. Everything is working fine apart from when I try
to use the python shell to return the objects names. I tried to skip
the step but when I tried to create the select menu of Polls for the
Choices all that was returned was "Poll Object" instead of the name.

This is what my model looks like at the moment

class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

def __unicode__(self):
return self.question


class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()

def __unicode__(self):
return self.choice

When I do
>>>from mysite.polls.models import Poll, Choice
>>>Poll.object.all()

I get "poll.object" instead of a name. Could anyone point out where I
am going wrong please?

Thanks

Dan Fairs

unread,
Oct 31, 2008, 10:46:16 AM10/31/08
to django-d...@googlegroups.com
>
> This is what my model looks like at the moment
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> def __unicode__(self):
> return self.question


Your indentation is wrong. The 'def __unicode__' line needs to be
intended to the same level as question and pub_date, else it won't be
considered part of the Poll class.

Cheers,
Dan

--
Dan Fairs <dan....@gmail.com> | http://www.fezconsulting.com/

Dan Fairs

unread,
Oct 31, 2008, 10:46:44 AM10/31/08
to django-d...@googlegroups.com
Sorry - should also have mentioned that this should be on django-users.

--

Andrew Cetnarskyj

unread,
Oct 31, 2008, 12:02:56 PM10/31/08
to django-d...@googlegroups.com
thanks Dan I had used tabs instead of spaces, I will subscribe to django-users for future problems

Andy


Reply all
Reply to author
Forward
0 new messages