Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#10640 closed (fixed)

Add `add_form_template` option to ModelAdmin

Reported by: dcramer Owned by: kmtracey
Component: contrib.admin Version: master
Severity: Keywords:
Cc: jcsackett 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 jcsackett 6 years ago.
Patch to add the requested behavior
add_form.diff (4.9 KB) - added by jcsackett 6 years ago.
Updated patch including missing template for tests and updated documentation.
add_form.2.patch (4.9 KB) - added by jcsackett 6 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 6 years ago by jacob

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by anonymous

  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

comment:3 Changed 6 years ago by anonymous

  • Owner changed from anonymous to nobody
  • Status changed from assigned to new

comment:4 Changed 6 years ago by jcsackett

  • Owner changed from nobody to jcsackett
  • Status changed from new to assigned

Changed 6 years ago by jcsackett

Patch to add the requested behavior

comment:5 Changed 6 years ago by jcsackett

  • 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 follow-up: Changed 6 years ago by jcsackett

  • Owner changed from jcsackett to kmtracey
  • Status changed from assigned to new

comment:7 Changed 6 years ago by jcsackett

  • Cc jcsackett added

comment:8 in reply to: ↑ 6 Changed 6 years ago by kmtracey

  • Needs documentation set
  • Owner changed from kmtracey 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 6 years ago by jcsackett

  • Owner changed from nobody to jcsackett
  • Status changed from new to assigned

Changed 6 years ago by jcsackett

Updated patch including missing template for tests and updated documentation.

Changed 6 years ago by jcsackett

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

comment:10 Changed 6 years ago by jcsackett

  • Needs documentation unset
  • Owner changed from jcsackett to kmtracey
  • Patch needs improvement unset
  • Status changed from assigned to 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 Changed 5 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:12 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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