Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#34365 closed Cleanup/optimization (wontfix)

add_form_template used as change_form_template when adding object when only declaring change_form_template

Reported by: Xander Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

Attachments (1)

change_form_template.patch (554 bytes ) - added by Xander 21 months ago.
Patch file

Download all attachments as: .zip

Change History (4)

by Xander, 21 months ago

Attachment: change_form_template.patch added

Patch file

comment:1 by Mariusz Felisiak, 21 months ago

Has patch: unset
Resolution: wontfix
Status: newclosed

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.

in reply to:  1 ; comment:2 by Xander, 21 months ago

Replying to 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.

in reply to:  2 comment:3 by Mariusz Felisiak, 21 months ago

Replying to 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 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.

Note: See TracTickets for help on using tickets.
Back to Top