我无法覆盖ModelForm保存方法.这是我收到的错误:
Exception Type: TypeError
Exception Value: save() got an unexpected keyword argument 'commit'
Run Code Online (Sandbox Code Playgroud)
我的目的是让表单为3个字段提交许多值,然后为这些字段的每个组合创建一个对象,并保存每个对象.在正确的方向上有用的推动将是王牌.
models.pyclass CallResultType(models.Model):
id = models.AutoField(db_column='icontact_result_code_type_id', primary_key=True)
callResult = models.ForeignKey('CallResult', db_column='icontact_result_code_id')
campaign = models.ForeignKey('Campaign', db_column='icampaign_id')
callType = models.ForeignKey('CallType', db_column='icall_type_id')
agent = models.BooleanField(db_column='bagent', default=True)
teamLeader = models.BooleanField(db_column='bTeamLeader', default=True)
active = models.BooleanField(db_column='bactive', default=True)
Run Code Online (Sandbox Code Playgroud)
forms.pyfrom django.forms import ModelForm, ModelMultipleChoiceField
from callresults.models import *
class CallResultTypeForm(ModelForm):
callResult = ModelMultipleChoiceField(queryset=CallResult.objects.all())
campaign = ModelMultipleChoiceField(queryset=Campaign.objects.all())
callType = ModelMultipleChoiceField(queryset=CallType.objects.all())
def save(self, force_insert=False, force_update=False):
for cr in self.callResult:
for c …Run Code Online (Sandbox Code Playgroud)