我的模型有很多布尔字段.我把它们分成了3组,我将它们渲染为MultipleChoiceFieldw/a modified CheckboxSelectMultiple.
现在我需要将这些数据保存回数据库.即,我需要将单个小部件返回的数据拆分为多个布尔列.我觉得这个方法合适save(),不是吗?
问题是,我该怎么做?像这样的东西?
def save(self, commit=True):
# code here
return super(MyForm, self).save(commit)
Run Code Online (Sandbox Code Playgroud)
如果是这样...... 我该如何设置值?
self.fields['my_field'].value = 'my_flag' in self.cleaned_data['multi_choice']
Run Code Online (Sandbox Code Playgroud)
或者其他的东西?所有数据存储在哪里?