Opened 5 years ago

Closed 5 years ago

#30742 closed New feature (wontfix)

ModelForm should allow passing update_fields to instance.save()

Reported by: Václav Řehák Owned by: nobody
Component: Forms Version: 2.2
Severity: Normal Keywords: modelform
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Model's save() method allows specifying which fields to update using update_fields kwarg (we are investigating this option to finetune db level permissions of our django instances).

However, using this feature with ModelForm is bit inconvenient as ModelForm.save() calls self.instance.save() making it impossible to pass the update_fields to instance.save().

I think that add update_field to ModelForm.save() should be pretty straightforward change without backwards compatibility issues

Change History (1)

comment:1 by Carlton Gibson, 5 years ago

Resolution: wontfix
Status: newclosed

I don't think this is worth the complication. It is easily implemented overriding save:

def save(self, commit=True):
    instance = super().save(commit=False)
    if commit:
        self.instance.save(update_fields=...)
        self._save_m2m()
    return instance

It's a marginal use-case, not justifying adding another Meta option here.

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