Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#10640 closed (fixed)

Add `add_form_template` option to ModelAdmin

Reported by: David Cramer Owned by: Karen Tracey
Component: contrib.admin Version: master
Severity: Keywords:
Cc: j.c.sackett Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In some use cases we've found that we need to slightly tweak our change templates. Typically this is because the change view isn't directly changing the object, but it's handling it in some other way.

One small problem that came across was there's no way to specify the add page's template versus the change page's template.

I propose simply modifying render_change_form, to check for add=True, and if it's present, check for add_form_template. If add_form_template is set in the ModelAdmin to a value it should look for that template first. If it's set to None, it should use the default templates (and not change_form_template).

Attachments (3)

add_form.patch (3.3 KB) - added by j.c.sackett 7 years ago.
Patch to add the requested behavior
add_form.diff (4.9 KB) - added by j.c.sackett 7 years ago.
Updated patch including missing template for tests and updated documentation.
add_form.2.patch (4.9 KB) - added by j.c.sackett 7 years ago.
.patch version of the updated patch, just to keep them in sync.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 8 years ago by Jacob

milestone: 1.2
Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by anonymous

Owner: changed from nobody to anonymous
Status: newassigned

comment:3 Changed 7 years ago by anonymous

Owner: changed from anonymous to nobody
Status: assignednew

comment:4 Changed 7 years ago by j.c.sackett

Owner: changed from nobody to j.c.sackett
Status: newassigned

Changed 7 years ago by j.c.sackett

Attachment: add_form.patch added

Patch to add the requested behavior

comment:5 Changed 7 years ago by j.c.sackett

Has patch: set

I've added a patch to add this behavior.

The patch also changes the regression tests to verify use of the custom change form on an existing instance, and the custom add form when adding. Previously the regression test used the add view to check the custom change form.

All tests appear to be passing on python 2.5.

comment:6 Changed 7 years ago by j.c.sackett

Owner: changed from j.c.sackett to Karen Tracey
Status: assignednew

comment:7 Changed 7 years ago by j.c.sackett

Cc: j.c.sackett added

comment:8 in reply to:  6 Changed 7 years ago by Karen Tracey

Needs documentation: set
Owner: changed from Karen Tracey to nobody
Patch needs improvement: set

Replying to jcsackett:

Sorry I did not get a chance to look at this during the sprint. A couple of things need to be fixed before this can be checked in. First the new template file for the test isn't in the patch, so the test fails. To get svn diff to include it you first need to svn add the file. (I'm guessing you used svn based on the patch, but if you're using another vcs likely you need to do something similar for the diff to pick up the added file.)

Also, the description of ModelAdmin.change_form_template in docs/ref/contrib/admin/index.txt (online here: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_form_template) needs to be updated to reflect the change, and a new bit need to be added to describe the new add_form_tempalte option.

If you can do both of those, upload a new diff, and update the needs doc and patch needs improvement flags when its done I'll take another look.

comment:9 Changed 7 years ago by j.c.sackett

Owner: changed from nobody to j.c.sackett
Status: newassigned

Changed 7 years ago by j.c.sackett

Attachment: add_form.diff added

Updated patch including missing template for tests and updated documentation.

Changed 7 years ago by j.c.sackett

Attachment: add_form.2.patch added

.patch version of the updated patch, just to keep them in sync.

comment:10 Changed 7 years ago by j.c.sackett

Needs documentation: unset
Owner: changed from j.c.sackett to Karen Tracey
Patch needs improvement: unset
Status: assignednew

Updated patch includes modified documentation detailing the add_form_template and changing the documentation of the change_form_template attribute.

Added the add_form.html template for the tests (forgot to svn add it before, kmtracey was right).

I think this should have everything now.

comment:11 Changed 7 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

(In [12216]) Fixed #10640 - Adds a add_form_template option to ModelAdmin. Thanks jcsackett.

comment:12 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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