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 w开发者_运维技巧ord Add
to something else
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.
You will need to update your Django admin templates. The template you're looking for is django/contrib/admin/templates/admin/change_list.html
. Look for addlink
, the line below that should be the word to change.
that's the name for your model.
Django use model's class name by default, but you can change it by Meta.verbose_name
class MyModel(models.Model):
name = models.CharField()
class Meta:
verbose_name = u"a_new_name"
精彩评论