Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 202625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:18:23+00:00 2026-05-11T17:18:23+00:00

I’m having trouble overriding a ModelForm save method. This is the error I’m receiving:

  • 0

I’m having trouble overriding a ModelForm save method. This is the error I’m receiving:

Exception Type:     TypeError  
Exception Value:    save() got an unexpected keyword argument 'commit'

My intentions are to have a form submit many values for 3 fields, to then create an object for each combination of those fields, and to save each of those objects. Helpful nudge in the right direction would be ace.

File 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)

File 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

File admin.py

class CallResultTypeAdmin(admin.ModelAdmin):
    form = CallResultTypeForm
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:18:23+00:00Added an answer on May 11, 2026 at 5:18 pm

    In your save you have to have the argument commit. If anything overrides your form, or wants to modify what it’s saving, it will do save(commit=False), modify the output, and then save it itself.

    Also, your ModelForm should return the model it’s saving. Usually a ModelForm’s save will look something like:

    def save(self, commit=True):
        m = super(CallResultTypeForm, self).save(commit=False)
        # do custom stuff
        if commit:
            m.save()
        return m
    

    Read up on the save method.

    Finally, a lot of this ModelForm won’t work just because of the way you are accessing things. Instead of self.callResult, you need to use self.fields['callResult'].

    UPDATE: In response to your answer:

    Aside: Why not just use ManyToManyFields in the Model so you don’t have to do this? Seems like you’re storing redundant data and making more work for yourself (and me :P).

    from django.db.models import AutoField  
    def copy_model_instance(obj):  
        """
        Create a copy of a model instance. 
        M2M relationships are currently not handled, i.e. they are not copied. (Fortunately, you don't have any in this case)
        See also Django #4027. From http://blog.elsdoerfer.name/2008/09/09/making-a-copy-of-a-model-instance/
        """  
        initial = dict([(f.name, getattr(obj, f.name)) for f in obj._meta.fields if not isinstance(f, AutoField) and not f in obj._meta.parents.values()])  
        return obj.__class__(**initial)  
    
    class CallResultTypeForm(ModelForm):
        callResult = ModelMultipleChoiceField(queryset=CallResult.objects.all())
        campaign = ModelMultipleChoiceField(queryset=Campaign.objects.all())
        callType = ModelMultipleChoiceField(queryset=CallType.objects.all())
    
        def save(self, commit=True, *args, **kwargs):
            m = super(CallResultTypeForm, self).save(commit=False, *args, **kwargs)
            results = []
            for cr in self.callResult:
                for c in self.campain:
                    for ct in self.callType:
                        m_new = copy_model_instance(m)
                        m_new.callResult = cr
                        m_new.campaign = c
                        m_new.calltype = ct
                        if commit:
                            m_new.save()
                        results.append(m_new)
             return results
    

    This allows for inheritance of CallResultTypeForm, just in case that’s ever necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In short: The only totally safe thing to do is… May 11, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer The order inserts/updates and deletes are made in the Entity… May 11, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer I think what you want is this: Dim query =… May 11, 2026 at 6:27 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.