[Django] #34365: add_form_template used as change_form_template when adding object when only declaring change_form_template

9 views
Skip to first unread message

Django

unread,
Feb 23, 2023, 7:59:56 AM2/23/23
to django-...@googlegroups.com
#34365: add_form_template used as change_form_template when adding object when only
declaring change_form_template
------------------------------------------------+------------------------
Reporter: xander-m2k | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
So when you declare change_form_template in your admin model.
Automatically, when trying to add an object in the admin panel, this form
also gets used. This is weird unexpected behavior.
(https://github.com/django/django/blob/main/django/contrib/admin/options.py#L1306)

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

Django

unread,
Feb 23, 2023, 8:00:17 AM2/23/23
to django-...@googlegroups.com
#34365: add_form_template used as change_form_template when adding object when only
declaring change_form_template
-------------------------------------+-------------------------------------
Reporter: xander-m2k | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:

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

* Attachment "change_form_template.patch" added.

Patch file

Django

unread,
Feb 23, 2023, 8:27:26 AM2/23/23
to django-...@googlegroups.com
#34365: add_form_template used as change_form_template when adding object when only
declaring change_form_template
-------------------------------------+-------------------------------------
Reporter: Xander | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* has_patch: 1 => 0
* resolution: => wontfix


Comment:

I don't see anything unexpected in this behavior. Moreover,
`render_change_form()` is a private API and proposed changes are backward
incompatible. Other than that, we have no other forms to choose.

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

Django

unread,
Feb 23, 2023, 8:34:47 AM2/23/23
to django-...@googlegroups.com
#34365: add_form_template used as change_form_template when adding object when only
declaring change_form_template
-------------------------------------+-------------------------------------
Reporter: Xander | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Xander):

Replying to [comment:1 Mariusz Felisiak]:


> I don't see anything unexpected in this behavior. Moreover,
`render_change_form()` is a private API and proposed changes are backward
incompatible. Other than that, we have no other forms to choose.

I know this is probably not the solution, but I don't agree on that it is
not unexpected behavior. In order to use the default add template (when
also using `change_form_template`), you have to declare `add_form_template
= "admin/change_form.html"`, which is unexpected in the sense that it is
non-logical and counter-intuitive. It should just use that default unless
declared otherwise. Not replace both when only `change_form_template` is
declared in your `CommonModelAdmin` implemented class.

--
Ticket URL: <https://code.djangoproject.com/ticket/34365#comment:2>

Django

unread,
Feb 24, 2023, 12:47:21 AM2/24/23
to django-...@googlegroups.com
#34365: add_form_template used as change_form_template when adding object when only
declaring change_form_template
-------------------------------------+-------------------------------------
Reporter: Xander | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:2 Xander]:


> In order to use the default add template (when also using
`change_form_template`), you have to declare `add_form_template =
"admin/change_form.html"`, which is unexpected in the sense that it is
non-logical and counter-intuitive. It should just use that default unless
declared otherwise. Not replace both when only `change_form_template` is
declared in your `CommonModelAdmin` implemented class.

The default change form is used when `add_form_template` is not declared.
When you change the `change_form_template` than it's used as a default for
`add_form_template`. I don't see anything "counter-intuitive" is this
behavior 🤔

Please [https://docs.djangoproject.com/en/stable/internals/contributing
/triaging-tickets/#closing-tickets follow the triaging guidelines with
regards to wontfix tickets] and take this to DevelopersMailingList (if you
don't agree) where you'll reach a wider audience and see what other think.

--
Ticket URL: <https://code.djangoproject.com/ticket/34365#comment:3>

Reply all
Reply to author
Forward
0 new messages