【发布时间】:2026-02-05 23:30:01
【问题描述】:
例如, 我有一个模型
class Question(models.Model):
question_text = models.TextField()
question_number = IntegerField(default=0)
我尝试做:
question_list = Question.objects.order_by('question_number')
#then save the queryset back to the database
我该怎么做?
【问题讨论】:
-
你不能......你的数据库不存储查询集,它存储单独的数据行。查询集是查询数据库的结果。你想在这里实现什么?您是否尝试 set the default ordering 从您的模型返回的数据?
-
您为什么要这样做?如果您希望问题按 question_number 排序,只需在获取时使用相同的 order_by 进行排序。