django_AttributeError: 'QuerySet' object has no attribute 'save'

问题描述:

使用save()想修改一个查询集合中的值,修改后使用集合进行save()操作,结果报错,mark下

代码如下:

>>> from polls.models import Question
>>> q = Question.objects.get(pk=1)
>>> choice  = q.choice_set.all()
>>> choice[0].choice_text
'test1'
>>> choice[0].choice_text = "橘子"
>>> choice.save()

报错如下:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'QuerySet' object has no attribute 'save'

原因分析:

choice是一个查询结果集,没有save的属性,无法进行保存。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章