Problem with Tutorial 1 - Django Version = 1.3

15 views
Skip to first unread message

Eiram

unread,
Jun 30, 2011, 9:57:46 AM6/30/11
to Django users
Greetings!!

In the past few days I have been trying to learn about Django. I
started doing the Tutorial 1. During the tutorial I'm getting a
strange error. I was hoping if someone can help me to understand what
I'm doing wrong and how can I fix it.

This is the code I had:

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 execute the command Poll(objetcs.all): I get as result the
following: class [<Poll: Poll object>, <Poll: Poll object>] when I;m
supposed to get as result [<Poll: What's up?>]

I don't know what is missing. If someone can help me I would
appreciate it. Thanks!!


Kenneth Gonsalves

unread,
Jun 30, 2011, 10:01:25 AM6/30/11
to django...@googlegroups.com
On Thu, 2011-06-30 at 06:57 -0700, Eiram wrote:
> Poll(objetcs.all)

Poll.objects.all()
--
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

Daniel Roseman

unread,
Jun 30, 2011, 10:05:29 AM6/30/11
to django...@googlegroups.com
Op donderdag 30 juni 2011 14:57:46 UTC+1 schreef Eiram het volgende:
Indentation! Both `def __unicode__` lines need to be at the same level as the lines above them.
--
DR. 

Jirka Vejrazka

unread,
Jun 30, 2011, 10:06:03 AM6/30/11
to django...@googlegroups.com
> 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 execute the command Poll(objetcs.all): I get as result the
> following: class [<Poll: Poll object>, <Poll: Poll object>] when I;m
> supposed to get as result [<Poll: What's up?>]
>
> I don't know what is missing. If someone can help me I would
> appreciate it. Thanks!!

Apart from the problem Kenneth pointed out, you seem to have the
indentation wrong. The "def __unicode__" belongs to the class, not on
the same level as the "class" word.

Cheers

Jirka

Jarilyn Hernandez

unread,
Jun 30, 2011, 10:19:46 AM6/30/11
to django...@googlegroups.com
Thanks for your responses. The problem was solved.

Best Regards,

Eiram


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Jarilyn M. Hernández
MS Computer Science
Polytechnic University of Puerto Rico

Cal Leeming [Simplicity Media Ltd]

unread,
Jun 30, 2011, 11:28:42 AM6/30/11
to django...@googlegroups.com
Hi OP,

Just as a side note, it's probably worth learning about how Python works before jumping straight into Django. (I'm assuming this based on __unicode__ did not have proper indentation). 

My apologies if I am wrong though!

Cal
Reply all
Reply to author
Forward
0 new messages