#33527 closed Cleanup/optimization (fixed)
Remove unnecessary code in ModelAdmin._changeform_view().
| Reported by: | Maxim Danilov | Owned by: | Dulalet |
|---|---|---|---|
| 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
Change History (10)
comment:1 by , 4 years ago
| Cc: | removed |
|---|---|
| Description: | modified (diff) |
comment:2 by , 4 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 4 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
def get(self, request,obj):
form = ModelForm(request.POST, request.FILES, instance=obj)
if form.instance :
formsets, inline_instances = self._create_formsets(request, form.instance, change=not add)
elif obj :
formsets, inline_instances = self._create_formsets(request, obj, change=not add)
comment:4 by , 4 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → new |
The ticket isn't fixed until changes are merged.
comment:5 by , 4 years ago
| Summary: | remove unnecessary code from patch before in ModelAdmin inlines save. → Remove unnecessary code in ModelAdmin._changeform_view(). |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Agreed, if add else obj is unnecessary. Maxim, would you like to prepare a patch?
comment:6 by , 4 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Hi all. I am new to Open Source and I want to make my first contribution to Django. I'd like to prepare a patch for this issue if no one minds. Thank you!
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,