[Fixed]-Alter Django admin change list title text

1👍

There is already ticket for ChangeList customization: http://code.djangoproject.com/ticket/9749. This will give the ability to change many additional aspects of admin application. Unfortunately there is no clean way to achieve your goals.

👤zgoda

36👍

Not sure if still relevant, but another way to do this would be passing the extra_content for the changelist_view method. For ex:

from django.contrib import admin

class MyCustomAdmin(admin.ModelAdmin):

    def changelist_view(self, request, extra_context=None):
        extra_context = {'title': 'Change this for a custom title.'}
        return super(MyCustomAdmin, self).changelist_view(request, extra_context=extra_context)

5👍

For current versions of Django:

class CustomChangeList(django.contrib.admin.views.main.ChangeList):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title = 'My Cool Title'

class MyAdmin(ModelAdmin):
    def get_changelist(self, request, **kwargs):
        return CustomChangeList

2👍

You can change the title on change page with extra_context in changelist_view() as shown below:

# "admin.py"

from django.contrib import admin
from .models import Person
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect

csrf_protect_m = method_decorator(csrf_protect)

@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
    @csrf_protect_m
    def changelist_view(self, request, extra_context=None):
        extra_context = {'title': 'This is a custom title.'} # Here
        return super().changelist_view(request, extra_context=extra_context)

This is how the title on change page looks like as shown below:

enter image description here

0👍

You can override the method and pass it the title in extra_content, see:

def change_view(self, request, object_id, form_url='', extra_context=None):

        extra_context = {'title': 'Hello Title'}

        return super(BlogAdmin, self).change_view(request, object_id,
            form_url, extra_context=extra_context)

0👍

As of Django 3.1.7

I think the OP is asking about the changelist "content" title (the one shown on the page below breadcrumbs, not in the browser tab title). Django sets it from the model’s verbose_name_plural (set in model class’ class Meta). If it is not explicitly set, Django uses the model class name with ‘s’ suffixed. Here is the code from Django admin change_list.html:

<!-- CONTENT-TITLE -->
{% block content_title %}
    <h1>{{ cl.opts.verbose_name_plural|capfirst }}</h1>
{% endblock %}

So if just setting the verbose_name_plural does not suffice/work for you, consider overriding the change_list.html template and do your thing in the {% block content_title %}. If it is too complicated to do in the template, you can pass your own context data to the admin template as given in the SO answer here:
Django how to pass custom variables to context to use in custom admin template?

👤amolbk

Leave a comment