#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)
Change History (15)
comment:1 by , 16 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:4 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 15 years ago
Attachment: | add_form.patch added |
---|
comment:5 by , 15 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.
follow-up: 8 comment:6 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:7 by , 15 years ago
Cc: | added |
---|
comment:8 by , 15 years ago
Needs documentation: | set |
---|---|
Owner: | changed from | to
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 , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 15 years ago
Attachment: | add_form.diff added |
---|
Updated patch including missing template for tests and updated documentation.
by , 15 years ago
Attachment: | add_form.2.patch added |
---|
.patch version of the updated patch, just to keep them in sync.
comment:10 by , 15 years ago
Needs documentation: | unset |
---|---|
Owner: | changed from | to
Patch needs improvement: | unset |
Status: | assigned → new |
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 , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch to add the requested behavior