Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customising Django Admin Interface

In Django Admin, in the changelist view there is a Add <model_name> button at the top right hand corner.

Does anyone have any idea how to change the default text in that button?

UPDATE

I want to change the word Add to something else

like image 848
super9 Avatar asked Mar 27 '26 00:03

super9


1 Answers

The changelist view renders the change_list.html file in django/contrib/admin/templates/admin directory.

Specifically, the snippet that you want to modify is

{% block content %}
  <div id="content-main">
    {% block object-tools %}
      {% if has_add_permission %}
        <ul class="object-tools">
          {% block object-tools-items %}
            <li>
              <a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
                {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
              </a>
            </li>
          {% endblock %}
        </ul>
      {% endif %}
    {% endblock %}

So the bad news is that your "Add" user interface string as you can see is hardcoded.

The good news is, you can still override it by creating your own change_list.html template in your own project templates/admin/ directory. The specifics are explained here in django docs:- https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

and specifically in your case, it is simply to override the object-tools block on your own change_list.html file.

like image 192
Calvin Cheng Avatar answered Mar 28 '26 12:03

Calvin Cheng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!