1👍
✅
First, make sure that the contents of models.py
match with what’s given in the tutorial
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self): # __str__ on Python 3
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question)
choice_text = models.CharField(max_length=200, default="")
votes = models.IntegerField(default=0)
def __unicode__(self): # __str__ on Python 3
return self.choice_text
Also make sure that the migrations are up to date.
If you’re running python 2, use __unicode__
else use __str__
.
That should solve the problem for you.
Source:stackexchange.com