3

Now I'm developing a feedback application,

So, the admin must see messages from users, filter them(read/unread) and mark them as important. I have already done all the functionality I need, but i cannot customize my headers. For example. There is a default header in change list(see the screenshot, this header is selected), How can I delete these headers or customize them?Screenshot

Great thanks in advance.

Alexey Sidash
  • 441
  • 4
  • 14

1 Answers1

6

Actually, the answer from @mayankTUM is not correct. It does not follow the django design philosophies and should not be implemented (@mayankTUM himself mentions one of the problems of his solution however there are many, many more)!

Basically, what you need to do can be done by overriding the admin templates. Because there are some problems with that (I will explain later), here's exactly what I did to solve your requirement:

  1. Created a directory named admin in my templates folder.
  2. Copied there the change_list.html template from <django>\contrib\admin\templates\admin\change_list.html.
  3. Added the following to the end of the new change_list.html: {% block content_title %}Hello world!{% endblock %}

Now, instead of "Select ... to change" it will print "Hello world!"

I have to notice that copying the whole change_list.html is not DRY - it'd be much better if I just created the file, made it extend from admin/change_list.html and add the content_title. However this is not working and will lead to infinite recursion (please check this bug report https://code.djangoproject.com/ticket/15053 ) -- this is the problem to which I was referring before. A better solution that copying over the whole template is discussed in the following questions:

Django: Overriding AND extending an app template and How to override and extend basic Django admin templates? and django override admin template

PS: My TEMPLATE_DIRS and TEMPLATE_LOADERS project settings are these:

TEMPLATE_DIRS = (
    PROJECT_PATH.child('templates'),
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)
Community
  • 1
  • 1
Serafeim
  • 14,962
  • 14
  • 91
  • 133