布尔字段未保存在模型表单中

时间:2010-08-05 18:15:55

标签: django django-forms

我有一个如下所示的表单类:

class ApplicationDetailsForm(ModelForm):
    worked_in_industry = forms.TypedChoiceField(coerce=int, 
                         choices=((1, 'Yes'), (0, 'No')), 
                         widget=forms.RadioSelect())

    class Meta:
        model = ApplicantDetails
        fields = ('work_experience', 'license_level', 'license_duration',      
                  'expected_salary')

字段worked_in_industryBooleanField我已修改为呈现为是/否单选按钮。我的问题是处理我的表单时没有保存该字段...除了单选按钮字段外,所有其他字段都保存正确。我的问题是什么?

在处理视图中,我还添加了:

if job.is_valid():
    application = job.save(commit=False)
    worked_in_industry = job.cleaned_data['worked_in_industry']

1 个答案:

答案 0 :(得分:0)

您应该在"worked_in_industry"元变量中包含fields

相关问题