I am just started out learning Python and also started looking into Django a little bit. So I copied this piece of code from the tutorial:
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def ___unicode__(self):
return self.choice #shouldn't this return the choice
When I play around with it in the shell, I just get the "question" of the Poll object, but for some reason it won't return of the "choice" of the Choice objects. I fail to see the difference. My output on the shell looks like this:
>>> Poll.objects.all()
[<Poll: What is up?>]
>>> Choice.objects.all()
[<Choice: Choice object>, <Choice: Choice object>, <Choice: Choice object>]
>>>
I was expecting for the Choice objects to return something else than "Choice object". Does anybody have an idea about where I failed and what I should look into?
EDIT: Way to make me feel like an idiot. Yes, the three underscores were the problem. I was looking at that for about an hour now.