Opened 15 years ago

Closed 14 years ago

Last modified 12 years ago

#10640 closed (fixed)

Add `add_form_template` option to ModelAdmin

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

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

Download all attachments as: .zip

Change History (15)

comment:1 by Jacob, 15 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

comment:2 by anonymous, 14 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:3 by anonymous, 14 years ago

Owner: changed from anonymous to nobody
Status: assignednew

comment:4 by j.c.sackett, 14 years ago

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

by j.c.sackett, 14 years ago

Attachment: add_form.patch added

Patch to add the requested behavior

comment:5 by j.c.sackett, 14 years ago

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 by j.c.sackett, 14 years ago

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

comment:7 by j.c.sackett, 14 years ago

Cc: j.c.sackett added

in reply to:  6 comment:8 by Karen Tracey, 14 years ago

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 by j.c.sackett, 14 years ago

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

by j.c.sackett, 14 years ago

Attachment: add_form.diff added

Updated patch including missing template for tests and updated documentation.

by j.c.sackett, 14 years ago

Attachment: add_form.2.patch added

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

comment:10 by j.c.sackett, 14 years ago

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 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

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

comment:12 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

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