#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 History (4)
by , 3 years ago
| Attachment: | change_form_template.patch added |
|---|
follow-up: 2 comment:1 by , 3 years ago
| Has patch: | unset |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
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.
follow-up: 3 comment:2 by , 3 years 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.
comment:3 by , 3 years ago
Replying to Xander:
In order to use the default add template (when also using
change_form_template), you have to declareadd_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 onlychange_form_templateis declared in yourCommonModelAdminimplemented 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.
Patch file