[Django] #30742: ModelForm should allow passing update_fields to instance.save()

15 views
Skip to first unread message

Django

unread,
Aug 30, 2019, 3:48:25 AM8/30/19
to django-...@googlegroups.com
#30742: ModelForm should allow passing update_fields to instance.save()
----------------------------------------+---------------------------
Reporter: Václav Řehák | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 2.2
Severity: Normal | Keywords: modelform
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+---------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/30742>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 2, 2019, 3:15:26 AM9/2/19
to django-...@googlegroups.com
#30742: ModelForm should allow passing update_fields to instance.save()
------------------------------+--------------------------------------

Reporter: Václav Řehák | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 2.2
Severity: Normal | Resolution: wontfix

Keywords: modelform | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => wontfix


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30742#comment:1>

Reply all
Reply to author
Forward
0 new messages