ModelForm
saveメソッドをオーバーライドするのに問題があります。これは私が受け取っているエラーです:
Exception Type: TypeError
Exception Value: save() got an unexpected keyword argument 'commit'
私の意図は、フォームに3つのフィールドの多くの値を送信させ、それらのフィールドの組み合わせごとにオブジェクトを作成し、それらの各オブジェクトを保存することです。正しい方向に役立つナッジはエースでしょう。
ファイルmodels.py
class 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)
ファイルforms.py
from 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 in self.campain:
for ct in self.callType:
m = CallResultType(self) # this line is probably wrong
m.callResult = cr
m.campaign = c
m.calltype = ct
m.save()
class Meta:
model = CallResultType
ファイルadmin.py
class CallResultTypeAdmin(admin.ModelAdmin):
form = CallResultTypeForm