Model Django Poll

Posted by MacPython on Stack Overflow See other posts from Stack Overflow or by MacPython
Published on 2010-05-11T13:29:49Z Indexed on 2010/05/11 13:34 UTC
Read the original article Hit count: 241

Filed under:
|
|
|
|

I followed the django tutorial here:

http://docs.djangoproject.com/en/dev/intro/tutorial01/

and now I am at creating a poll.

The code below works fine until I want to create choices, where for some reason I always get this error message:

line 22, in unicode return self.question

AttributeError: 'Choice' object has no attribute 'question'

Unfortunatley, I dont understand where I made an error. Any help would be greatly appreciated.

Thanks for the time!

CODE:

import datetime
from django.db import models

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.question

© Stack Overflow or respective owner

Related posts about python

Related posts about django