Opened 4 years ago
Last modified 4 years ago
#33527 closed Cleanup/optimization
remove unnecessary code from patch before in ModelAdmin inlines save. — at Version 1
| Reported by: | Maxim Danilov | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | 4.0 |
| Severity: | Normal | Keywords: | modeladmin, inlinemodel |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
In #33111, the following code was added:
form = ModelForm(request.POST, request.FILES, instance=obj) formsets, inline_instances = self._create_formsets(request, form.instance if add else obj, change=not add)
it is all ok, but if we have:
form = ModelForm(request.POST, request.FILES, instance=obj)
this is superabundant:
form.instance if add else obj
I think, it should be:
form = ModelForm(request.POST, request.FILES, instance=obj) formsets, inline_instances = self._create_formsets(request, form.instance, change=not add) # or # formsets, inline_instances = self._create_formsets(request, obj, change=not add)
The same changes is possible to made in code-block for request.GET
Note:
See TracTickets
for help on using tickets.
I don't see any test failures with the following patch, so if it's needed, perhaps a regression test would be useful.
django/contrib/admin/options.py
if add else obj,