#33527: remove unnecessary code from patch before in ModelAdmin inlines save.
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage:
inlinemodel | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):
* cc: Mariusz, Felisiak (removed)
Old description:
> i see in Patch from https://code.djangoproject.com/ticket/33111
> 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
New description:
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
--
Comment:
I don't see any test failures with the following patch, so if it's needed,
perhaps a regression test would be useful.
{{{ #!diff
diff --git a/django/contrib/admin/options.py
b/django/contrib/admin/options.py
index b1aa610d43..64be087bf1 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -1787,7 +1787,7 @@ class ModelAdmin(BaseModelAdmin):
form = ModelForm(request.POST, request.FILES, instance=obj)
formsets, inline_instances = self._create_formsets(
request,
- form.instance if add else obj,
+ form.instance,
change=not add,
)
form_validated = form.is_valid()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.4a8532c38940f3281e56f4a638dbca4c%40djangoproject.com.