现在我正在开发一个反馈应用程序,
因此,管理员必须看到来自用户的消息,过滤它们(已读/未读)并将其标记为重要。
我已经完成了我需要的所有功能,但我无法自定义我的标题。
例如。
更改列表中有一个默认标题(参见屏幕截图,选中此标题),
如何删除这些标题或自定义它们?
非常感谢提前。
答案 0 :(得分:6)
实际上,@ mayankTUM的答案是不正确。它不遵循django design philosophies而不应该实现(@mayankTUM自己提到了他解决方案的一个问题,但是有很多甚至更多)!
基本上,您需要做的事情可以由overriding the admin templates完成。因为有一些问题(我稍后会解释),这正是什么 我做了解决你的要求:
admin
文件夹中创建了一个名为templates
的目录。change_list.html
<django>\contrib\admin\templates\admin\change_list.html
模板
change_list.html
:{% block content_title %}Hello world!{% endblock %}
现在,不是“选择......改变”,而是打印“Hello world!”
我必须注意到复制整个 change_list.html
并不是干的 - 如果我刚刚创建了文件,它会更好,从admin/change_list.html
扩展而来添加content_title
。然而,这不起作用,将导致无限递归(请检查此错误报告https://code.djangoproject.com/ticket/15053) - 这是我之前提到的问题。在以下问题中讨论了复制整个模板的更好解决方案:
Django: Overriding AND extending an app template 和 How to override and extend basic Django admin templates?和 django override admin template
PS:我的TEMPLATE_DIRS
和TEMPLATE_LOADERS
项目设置如下:
TEMPLATE_DIRS = (
PROJECT_PATH.child('templates'),
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)