It looks like the issue is one of indentation. There's nothing for
"self" to refer to if the method isn't part of the class.
--And you're probably better off using __unicode__ than __str__
Try:
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateF
> I'm just going through the mysite tutorial and can't seem to get the
> __str__() method to work when adding it to the two classes, I still
> get [].
>
> polls/models.py:
>
> from django.db import models
> import datetime
>
> class Poll(models.Model):
>question = models.CharField(maxlength=20
Looks like your indentation is wrong (assuming it's not just a copy/paste
issue).
Remember python code needs to be indented correctly in order to work. Your
def __str__(self): line needs to start at the same indentation as the
attributes (question/pub_date) inside your class.
Tim.
On Wednes
Hello,
I'm just going through the mysite tutorial and can't seem to get the
__str__() method to work when adding it to the two classes, I still
get [].
polls/models.py:
from django.db import models
import datetime
class Poll(models.Model):
question = models.CharField(maxlength=200)
pub
4 matches
Mail list logo