返回信息流首先我的models是这样写的
myapp/models.py:
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,related_name='Choice_set')
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
migrate之后在python shell中:
>>>q = Question.objects.all()
[<Question: what is new??>]说明Question时有值的,但是:
>>>q.Choice_set.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'Choice_set'
求问:应该怎样添加Choice的值呢?
这是一条镜像帖。来源:北邮人论坛 / python / #13269同步于 2016/4/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
Django中model层中关于外键的问题
upupup123
2016/4/10镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。