Skip to content

Instantly share code, notes, and snippets.

@squio
Last active April 7, 2022 14:11
Show Gist options
  • Save squio/3619c4dfe079281ac722aa762e33be38 to your computer and use it in GitHub Desktop.
Save squio/3619c4dfe079281ac722aa762e33be38 to your computer and use it in GitHub Desktop.
Override Django Admin submit_line.html

Enhancing https://stackoverflow.com/posts/65938495/

It is also possible to override/extend the innermost {% block submit-row %} like so:

{% extends 'admin/submit_line.html' %}
{% load i18n admin_urls %}

{% block submit-row %}
    {% if extra_button_allowed %}
        <input type="submit" value="Get me tea" name="_get_tea" />
    {% endif %}
    {{ block.super }}
{% endblock %}

This way you maintain the original behaviour of the 'Save' buttons.

The submit-row block comes from the django/contrib/admin/templates/admin/submit_line.html template.

As noted by @peter-kilczuk you have to save this to a folder named templates/admin/<your-app>/<yourmodelname>/submit_line.html; no need to set the change_form_template in your ModelAdmin class.

NOTE that yourmodelname is the slug name of YourModelName and all characters are in lowercase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment