{{{
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
--
Ticket URL: <https://code.djangoproject.com/ticket/33527>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* 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>
* owner: nobody => shirani98
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:2>
* status: assigned => closed
* resolution: => fixed
Comment:
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)
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:3>
* status: closed => new
* resolution: fixed =>
Comment:
The ticket isn't fixed until changes are merged.
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:4>
* stage: Unreviewed => Accepted
Comment:
Agreed, `if add else obj` is unnecessary. Maxim, would you like to prepare
a patch?
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:5>
* owner: Mahdi Shirani => Dulalet
* status: new => assigned
Comment:
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!
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:6>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
Comment:
[https://github.com/django/django/pull/15465 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e0442a628eb480eac6a7888aed5a86f83499e299" e0442a62]:
{{{
#!CommitTicketReference repository=""
revision="e0442a628eb480eac6a7888aed5a86f83499e299"
Fixed #33527 -- Removed unnecessary code in ModelAdmin._changeform_view().
Co-authored-by: Daulet1 <d.ab...@thefactory.kz>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33527#comment:8>