1
我有這個真正奇怪的問題布萊恩,並沒有能夠弄明白。我有一個帶有ChoiceField的表單,我從一個模型對象中加載數據並將其設置爲表單的初始值。實際上只有一半的字段被設置爲該對象指定的初始值。Django ChoiceField初始值未設置爲所有ChoiceFields
繼承人的形式
sku = forms.CharField(max_length=200, required=True)
weight = forms.DecimalField(min_value=.1, max_digits=4, decimal_places=1, required=True, help_text="Enter Weight In Pounds")
mail_class = forms.ChoiceField(choices=MAIL_CLASS, required=True)
package_type = forms.ChoiceField(choices=PACKAGE_TYPE, required=True)
shipping_rule = forms.IntegerField(min_value=1, required=False)
new_weight = forms.DecimalField(min_value=.1, max_digits=4, decimal_places=1, required=False, help_text="Enter Weight for new shipping method In Pounds")
new_mail_class = forms.ChoiceField(choices=MAIL_CLASS, required=False, initial='None')
new_package_type = forms.ChoiceField(choices=PACKAGE_TYPE, required=False, initial='None')
max_shipping_rule = forms.IntegerField(min_value=2, required=False)
max_weight = forms.DecimalField(min_value=.1, max_digits=4, decimal_places=1, required=False, help_text="Enter Weight for new shipping method In Pounds")
max_mail_class = forms.ChoiceField(choices=MAIL_CLASS, required=False, initial='None')
max_package_type = forms.ChoiceField(choices=PACKAGE_TYPE, required=False, initial='None')
而且繼承人是我設置視圖
data = {
'sku': shipping_info.sku,
'weight': shipping_info.weight,
'mail_class': shipping_info.mailclass,
'package_type': shipping_info.packagetype,
'shipping_rule': shipping_info.shippingrule,
'new_weight': shipping_info.newweight,
'new_mail_class': shipping_info.newmailclass,
'new_package_type': shipping_info.newpackagetype,
'max_shipping_rule': shipping_info.maxshippingrule,
'max_weight': shipping_info.newmaxweight,
'max_mail_class': shipping_info.maxmailclass,
'max_package_type': shipping_info.maxpackagetype
}
form = ShippingType(initial=data)
只是問題是mail_class choicefields將被設置爲在模板中的權值。儘管package_type只是在第一個選項上設置的。
我已經檢查越來越把值作爲inital,這一切
任何想法相匹配,以選擇......?