开发者

Boolean fields not saving in a model form

开发者 https://www.devze.com 2023-01-10 04:46 出处:网络
I have a form class that looks like this: class ApplicationDetailsForm(ModelForm): worked_in_industry = forms.TypedChoiceField(coerce=int,

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

精彩评论

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