在Django管理主页上添加简单漂亮的快捷方式。
1.安装
pip install django-admin-shortcuts
2在settings.py注册django-admin-shortcuts
INSTALLED_APPS = [
'admin_shortcuts',
'django.contrib.admin',
.......
]
3.添加ADMIN_SHORTCUTS设置
ADMIN_SHORTCUTS = [ { 'title': 'Authentication', 'shortcuts': [ { 'title': 'Groups', 'url_name': 'admin:auth_group_changelist', 'has_perms': ['example.change_group', 'example.delete_group'], }, { 'title': 'Add user', 'url_name': 'admin:auth_user_add', 'test_func': 'example.utils.has_perms_to_users', }, ] },]
设置示例
ADMIN_SHORTCUTS = [ { 'shortcuts': [ { 'url': '/', 'open_new_window': True, }, { 'url_name': 'admin:logout', }, { 'title': 'Users', 'url_name': 'admin:auth_user_changelist', 'count': 'example.utils.count_users', }, { 'title': 'Groups', 'url_name': 'admin:auth_group_changelist', 'count': 'example.utils.count_groups', 'has_perms': ['example.change_group', 'example.delete_group'], }, { 'title': 'Add user', 'url_name': 'admin:auth_user_add', 'test_func': 'example.utils.has_perms_to_users', 'url_name': 'admin:auth_user_add', 'has_perms': 'example.utils.has_perms_to_users', }, ] }, { 'title': 'CMS', 'shortcuts': [ { 'title': 'Pages', 'url_name': 'admin:index', }, { 'title': 'Files', 'url_name': 'admin:index', }, { 'title': 'Contact forms', 'icon': 'columns', 'url_name': 'admin:index', 'count_new': '3', }, { 'title': 'Products', 'url_name': 'admin:index', }, { 'title': 'Orders', 'url_name': 'admin:index', 'count_new': '12', }, ] },]ADMIN_SHORTCUTS_SETTINGS = { 'show_on_all_pages': True, 'hide_app_list': True, 'open_new_window': False,}
最终效果
可选设置
ADMIN_SHORTCUTS_SETTINGS = { 'show_on_all_pages': False, 'hide_app_list': False, 'open_new_window': False,}
作用说明:
自定义外观
更改CSS覆盖模板页面templates/admin_shortcuts/base.css
要更改漂亮的图标,可以指定ADMIN_SHORTCUTS_CLASS_MAPPINGS的引用
项目github:https://github.com/alesdotio/django-admin-shortcuts