1
이 문제는 정말 이상한 일이며 해결하지 못했습니다. ChoiceFields가있는 양식이 있고, 모델 개체의 데이터를로드하고이를 양식의 초기 값으로 설정합니다. 필드의 절반 만 실제로 개체가 지정한 초기 값으로 설정됩니다.Django ChoiceField 모든 ChoiceFields에 대한 초기 값 설정이 없습니다.
Heres는 폼
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')
그리고 heres는 내가보기
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에 넣어지고 확인하고 모두가 ... 선택까지
어떤 아이디어와 일치?