change_form

the change_form.html provided by jmb.jadmin is already configure to

  • prepare for autocompletion
  • prepare for ajax_inlines / admin_tabs

Adding buttons in change_form

A templatetags used in ajax_inlines provides a way to easily add buttons to add actions on single records in the same place where “save” is.

To add such a button you need to overwrite change_form.html and add an argument extra_buttons_include to submit_row2 with the file that will be included:

{% block submit_buttons_top %}
    {% if change %}
        {% submit_row2 extra_buttons_include="admin/myapp/template/buttons.html" %}
    {% else %}
        {% submit_row2 %}
    {% endif %}
{% endblock %}

And the included file can be something as:

{% load i18n %}
<input type="submit" value="{% trans 'push template' %}" name="push_template" {{ onclick_attrib }}/>

Clearly you will also add a response_change that can resemmble te following code:

def response_change(self, request, obj):

    if 'push_template' in request.POST:
        try:
            <your code>
            messages.info(request, "Template pushed to main server")
        except BlablaError:
            pass

    return super(TemplateAdmin, self).response_change(request, obj)

Previous page

← Admin tabs

Next page

→ Ajax inlines

This Page