Login

Adding buttons to submit line in a Admin page

Author:
marinho
Posted:
May 12, 2008
Language:
Python
Version:
.96
Tags:
template ajax javascript admin query
Score:
3 (after 3 ratings)

Attention: this snippet depends on jQuery library to works

The Admin templates hierarchy does not allow you change the submit line (that buttons bar in the footer of the change view of a model class).

This code shows how to resolve this, using a simple javascript trick. You can read the code and implement using your favorite javascript library (instead of jQuery) or pure JavaScript.

This example regards to User Profile, a common used model class that adds custom fields to a user in the authentication system.

To use this, you must put this template code in a file with the following name:

templates/admin/auth/user/change_form.html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{% extends "admin/change_form.html" %}
{% load i18n %}

{% block extrahead %}{{ block.super }}

<script src="/media/js/jquery.js"></script>
<script>
    $(document).ready(function() {
        $('.move_to_submit_row').insertBefore('.submit-row>input:first');
    });
</script>
{% endblock extrahead %}

{% block after_field_sets %}{{ block.super }}

<input value="{% trans "Profile" %}"
 onclick="javascript: window.location='/admin/central/userprofile/{{ original.get_profile.id }}/'"
 class="move_to_submit_row" type="button"/>
{% endblock after_field_sets %}

More like this

  1. Confirm alert if the user navigates away without saving changes by mrazzari 6 years ago
  2. Admin actions as buttons instead of a menu by andybak 5 years, 5 months ago
  3. Dynamically add inlines by MasonM 6 years, 1 month ago
  4. Collapsed stacked inlines by Aneon 6 years, 2 months ago
  5. Admin Input Field Character Count via jQuery by joshman 6 years, 7 months ago

Comments

itavor (on May 14, 2008):

Nice! I already include jQuery in admin for most of my sites and use it to do other customizations, this is very easy to add and very useful.

#

Please login first before commenting.