本文介绍了如何在 Django ModelForm 中订购字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个订单"模型:
class Order(models.Model):
date_time=models.DateTimeField()
# other stuff
我正在使用 Django ModelForm 类来呈现表单,但我想分别显示日期和时间小部件.我想出了这个:
And I'm using Django ModelForm class to render a form, but I want to display date and time widgets separately. I've came up with this:
class Form(forms.ModelForm):
class Meta:
model = Order
exclude = ('date_time',)
date = forms.DateField()
time = forms.TimeField()
问题是我想把这些字段放在其他东西"之间
The problem is that I want to put these fields somewhere between 'other stuff'
推荐答案
您可以使用:
class Meta:
fields = [ ..., 'date', 'time', ... ]
查看文档:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changed-the-order-of-fields
这篇关于如何在 Django ModelForm 中订购字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!