开发者

Boolean fields not saving in a model form

I have a form class that looks like this:

class ApplicationDetailsForm(ModelForm):
    worked_in_industry = forms.TypedChoiceField(coerce=int, 
                         choices=((1, 'Yes'), (0, 开发者_如何学Python'No')), 
                         widget=forms.RadioSelect())

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

The field worked_in_industry is a BooleanField that I've modified to be rendered as Yes/No radio buttons. My problem is that the field isn't saved when my form is processed...all the other fields are saved correctly except the radio button fields. What's my problem?

In the processing view, I've also added:

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


you should include "worked_in_industry" in the fields Meta variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜