I just started with Django, and I'm following https://docs.djangoproject.com/en/1.10/intro/tutorial02/中提取 src。
我在shell中运行Question.objects.all()时收到shell的错误。我也跑了dir(问题)并说它不存在,但我知道它确实存在。重新启动了表/数据库,因为我编辑了几次models.py并且它没有接受任何更改。我还添加了unicode方法,但没有解决它。请提前感谢您的帮助。 这是我的models.py
from __future__ import unicode_literals
from django.db import models
# Create your models here
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.Question
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=8)
def __unicode__(self):
return self.Choice
答案 0 :(得分:0)
为初学者更改__unicode__
方法
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question_text
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=8)
def __unicode__(self):
return self.choice_text
答案 1 :(得分:0)