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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
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.