Python中文
首页
教程
问答
标签
搜索
登录
注册
Django modelformset order帴
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我想使用一个Django(1.4)modelformset,在这个模型中,当表单集被加载时,表单将按照我在模型中的exam_date字段排列。我创建了一个简单的模型集</p> <pre> class BaseExamDateFormSet(BaseModelFormSet): def __init__(self, *args, **kwargs): super(BaseExamDateFormSet, self).__init__(*args, **kwargs) self.queryset = models.ExamDate.objects.all().order_by('exam_date') </pre> <p>如您所见,我已经按照 <a href="https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#changing-the-queryset" rel="nofollow">django docs</a>(稍后我还将更改其clean方法,但现在不重要)。之后,我在视图中使用它来创建表单集:</p> ^{pr2}$ <p>我的问题是,当呈现formset时,表单中的数据总是以相同的顺序(probaby by id)而不管order\u by属性的值是什么:(</p> <p>我应该在ExamDate模型中设置默认的order by吗?不过,我真的不喜欢这种解决办法:(</p> <p>蒂娅!在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>再找了一下,我找到了一个解决办法!在</p> <p>我忽略了queryset属性,并将以下方法添加到BaseExamDateFormSet:</p> <pre> def get_queryset(self): return models.ExamDate.objects.all().order_by('exam_date') </pre> <p>但是我还不知道为什么queryset属性不起作用。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
pyVISA GPIB GET(组执行触发器)
8 回答
Pyvisa IOerror设备:Korad K3005d电源
3 回答
PyVISA mac OS X(山狮)安捷伦33250
10 回答
Pyvisa Pyusb无法加载大于1 MB的序列
9 回答
pyVisa RS232太慢
8 回答
PyVISA RS232超时错误(安捷伦电源)
7 回答
PyVISA SCPI命令和查询(值更新问题)
2 回答
PyVISA SerialInstrument需要硬重置才能在故障后连接
6 回答
pyvisa,未找到函数viOpen
8 回答
pyVISA:以编程方式将仪器返回到本地模式
4 回答
pyvisa:接口类型是什么意思?
2 回答
pyvisa.errors.VisaIOError:VI_ERROR_TMO(1073807339):操作完成前超时
2 回答
PyVisa“更复杂的示例”根本不运行Keithley 2400不理解的命令
9 回答
PyVisapy后端
4 回答
PyVISA不能写入超过7F的十六进制字符
9 回答
PYVISA中的ENUM模块和cStringIO模块
2 回答
PyVisa代码的图形用户界面
7 回答
Pyvisa使用按键电源超时
8 回答
PyVISA和Kethley 2701只能从一个通道获取结果
4 回答
PyVisa和Printing New D
1 回答