最初に、Traceback がないことを述べておきます。やるべきことをやらないだけです。
これらは、アプリのデータのモデルを定義する 2 つのクラスです。
from django.db import models
import datetime
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self): # Python 3: def __str__(self):
return self.question
def was_published_recently(self):
return self.pub_date.date() == datetime.date.today()
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self): # Python 3: def __str__(self):
return self.choice_text
ここにユニコードのコードを追加します。
def __unicode__(self):
return self.question
Django API 呼び出しがオブジェクトに関するより有益な情報を返すようにすることになっています。API 呼び出しは次のとおりです。
# objects.all() displays all the polls in the database.
>>> Poll.objects.all()
これは、Poll.objects.all()の非有益な戻り値です:
>>> Poll.objects.all()
[<Poll: Poll object>]
unicode メソッドを追加した後に表示されるはずのより有益な回答は、次のようになります。
>>> Poll.objects.all()
[<Poll: What's up?>]
私が経験している問題/エラーは、有益でない回答がまだ表示されていることです。