Search code examples
htmldjangomodel-view-controllerdjango-templatesdjango-admin

How do I change the default buttons in django?


In django admin, models have default buttons, how can I change the name of these buttons?

enter image description here


Solution

  • You can override the template. Indeed, this template is located at admin/submit_line.html.

    You can however override it, by just picking an app, and adding it to the template directory of that app, so if the app is named some_app, it is some_app/tempates/admin/submit_line.html, and that app should be loaded before the django.contrib.admin app, or appear in the DIRS of the template engine.

    The template is however not very easy to manipulate: it will need to take into account permissions, making it rather complicated, the original template looks like:

    {% load i18n admin_urls %}
    <div class="submit-row">
    {% block submit-row %}
    {% if show_save %}<input type="submit" value="{% translate 'Save' %}" class="default" name="_save">{% endif %}
    {% if show_save_as_new %}<input type="submit" value="{% translate 'Save as new' %}" name="_saveasnew">{% endif %}
    {% if show_save_and_add_another %}<input type="submit" value="{% translate 'Save and add another' %}" name="_addanother">{% endif %}
    {% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% translate 'Save and continue editing' %}{% else %}{% translate 'Save and view' %}{% endif %}" name="_continue">{% endif %}
    {% if show_close %}
        {% url opts|admin_urlname:'changelist' as changelist_url %}
        <a href="{% add_preserved_filters changelist_url %}" class="closelink">{% translate 'Close' %}</a>
    {% endif %}
    {% if show_delete_link and original %}
        {% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
        <a href="{% add_preserved_filters delete_url %}" class="deletelink">{% translate "Delete" %}</a>
    {% endif %}
    {% endblock %}
    </div>