Alter Django change title of change list title

I am creating some custom views for the Django admin interface that use the standard change list as an intermediate step. This works fine, except that the H1 change list page is “Select an object to change.” “Change” is not a valid verb for an action that a user will perform in my user views.

I found django.contrib.admin templates that control the layout of change list pages ( change_list.html and change_list_results.html ), but I cannot find where the title will be from. I assume this is a variable passed by some kind of?

How can I redefine this text with something less misleading, for example. "Select an object" instead of "Select an object to modify"? I'm fine, changing it in all the change list lists, not just the ones I'm trying to configure; but I would prefer a solution that is an override rather than modifying the django.contrib.admin code if possible.

Update: I found the view responsible for the change list, main.py in django\contrib\admin\views . The self.title variable on line 69 (Django 1.0). I got the result I'm looking for by editing this line

 self.title = (self.is_popup and ugettext('Select %s') % force_unicode(self.opts.verbose_name) or ugettext('Select %s to change') % force_unicode(self.opts.verbose_name)) 

to read

 self.title = (self.is_popup and ugettext('Select %s') % force_unicode(self.opts.verbose_name) or ugettext('Select %s') % force_unicode(self.opts.verbose_name)) 

Anyway, I would be interested to hear the best way to achieve the same result, which is not related to hacking the django.contrib.admin code - it looks like there is already an opportunity to have a title so d like it, but I'm not sure how to call it?

+6
django django-admin
source share
3 answers

There is already a ticket for setting ChangeList : http://code.djangoproject.com/ticket/9749 . This will provide an opportunity to change many additional aspects of the admin application. Unfortunately, there is no clean way to achieve your goals.

+2
source share

Not sure if this is still relevant, but another way to do this would be to pass extra_content to the changelist_view method. For example:

 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) 
+6
source share

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 
0
source share

All Articles