我正在从 https://docs.djangoproject.com/en/dev/intro/tutorial01/编写我的第一个 django 应用程序, 我遇到了 2 个问题。
我的 Models.py 是
从 django.db 导入模型
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def _unicode_(self):
return self.question self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def _unicode_(self):
return self.question
我的第一个错误是当我这样做的时候
python manage.py shell
from mysite.myapp.models import Poll,Choice
p = Poll(question="What Your Name",pub_date"1990-02-04")
p.save()
Poll.objects.all()
[<Poll: Poll object>, <Poll: Poll object>]
为什么它不显示 { 民意调查:怎么了?} 反而
[<Poll: Poll object>, <Poll: Poll object>]
我的第二个问题是当我输入
p = Poll.objects.get(id=1)
p.question.objects.all()
我得到这个错误
AttributeError: 'unicode' object has no attribute 'objects'
我如何解决它?