Opened 8 years ago

Closed 8 years ago

#26439 closed New feature (wontfix)

ModelForm.save() should accept the "using" keyword argument

Reported by: Andreas Poisel Owned by: nobody
Component: Forms Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Model.save() accepts the using keyword argument to explicitly chose a database connection. ModelForm.save() should offer the same functionality:

File django/forms/models.py:

def save(self, commit=True, using=None):
    if self.errors:
        raise ValueError(
            "The %s could not be %s because the data didn't validate." % (
                self.instance._meta.object_name,
                'created' if self.instance._state.adding else 'changed',
            )
        )
    if commit:
        # If committing, save the instance and the m2m data immediately.
        self.instance.save(using=using)
        self._save_m2m()
    else:
        # If not committing, add a method to the form to allow deferred
        # saving of m2m data.
        self.save_m2m = self._save_m2m
    return self.instance

Change History (1)

comment:1 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

A similar proposal was closed as wontfix in #8672 with the suggestion to use:

obj = form.save(commit=False)
obj.save(using=using)

Feel free to start a thread on the DevelopersMailingList if you disagree with this decision.

Note: See TracTickets for help on using tickets.
Back to Top