我通過他們的網站上的教程學習Django,我遇到了一個奇怪的問題。在這個step當我到達的部分,我進入的Unicode代碼片段,這樣Python和Unicode
>>> Poll.objects.all()
將返回不在此
[<Poll: Poll object>]
,但這樣的事情
[<Poll: What's up?>]
由於某種原因,代碼只適用於我複製和粘貼時,而不是當我輸入時。任何想法,爲什麼發生這種情況?
::
所以在這裏是不會在評論中格式化代碼:
from django.db import models
import datetime
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def was_published_today(self):
return self.pub_date.date() ==datetime.date.today()
def __unicode__(self):
return self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
縮進可能是錯誤的。告訴我們你輸入的內容。 –
你能發佈你的投票模型代碼嗎? – mwan
你可以使用__unicode __(個體經營)方法 – timger