Django: How to override form.save()?

后端 未结 1 360
天命终不由人
天命终不由人 2020-12-04 18:44

My model has quite a few boolean fields. I\'ve broken these up into 3 sets which I\'m rendering as a MultipleChoiceField w/ a modified CheckboxSelectMulti

相关标签:
1条回答
  • 2020-12-04 19:21

    The place you want your data to be stored is your new model instance:

    def save(self, commit=True):
        instance = super(MyForm, self).save(commit=False)
        instance.flag1 = 'flag1' in self.cleaned_data['multi_choice'] # etc
        if commit:
            instance.save()
        return instance
    
    0 讨论(0)
提交回复
热议问题