Adding button to admin change form

880 views
Skip to first unread message

Aaron

unread,
Oct 26, 2009, 12:45:39 PM10/26/09
to Django users
I need to add a button to the admin change form of certain models,
which would be placed among the save buttons. I've tried overriding
the template submit_line.html, but I am coming under the impression
that this is not possible unless I override the template for my entire
project.

I need this button so that I can write a view or some other kind of
handler that is able to access the model form contained in the admin
change form page. If using the button, I'd override the add_view and
change_view methods of the appropriate ModelAdmin, and do something
special if "_mybutton" is in the POST data. If adding a button to the
change form is not possible, is it possible to add some other link to
the page that would allow me to access the form object?

Mikhail Korobov

unread,
Oct 26, 2009, 4:06:49 PM10/26/09
to Django users
You should override change_form.html template and save it as

/your_project/templates/admin/your_app/change_form.html

or

/your_project/templates/admin/your_app/your_model/change_form.html

Aaron

unread,
Oct 27, 2009, 8:42:53 AM10/27/09
to Django users
On Oct 26, 5:06 pm, Mikhail Korobov <kmik...@googlemail.com> wrote:
> You should override change_form.html template and save it as
>
> /your_project/templates/admin/your_app/change_form.html
>
> or
>
> /your_project/templates/admin/your_app/your_model/change_form.html

Thank you.

I ended up creating my own tag to repace {% submit_row %} inside of
change_form.html. I was able to copy the python code from the admin
package, so I just had to edit submit_line.html (which I renamed) to
include the extra button and change_form.html to load the new tag.
Reply all
Reply to author
Forward
0 new messages