django-admin-bootstrap
django-admin-bootstrap copied to clipboard
Allow sidebar customization
Hello, should you be interested in including this feature in the main project, please let me know if you require any modification from my side before merging this PR.
Purpose
The main purpose is to allow, optionally, a complete customization of the sidebar and admin index, when the grouping of models by apps is not the better way to organize the admin.
To obtain this, I adapted some ideas from "django-admin-index" (https://github.com/maykinmedia/django-admin-index).
Sample usage
- add "BOOTSTRAP_ADMIN_SIDEBAR_MENU_CALLBACK" to project settings:
file "settings.py":
BOOTSTRAP_ADMIN_SIDEBAR_MENU_CALLBACK = 'admin_ex.sidebar.sidebar_config'
- supply an suitable menu list:
file "admin_ex/sidebar.py":
from django.utils.translation import ugettext_lazy as _
BOOTSTRAP_ADMIN_SIDEBAR_MENU_ITEMS = [
{
"name": _("Backend"),
"name": _("Backend"),
"app_label": 'backend',
"items": [
{'model': "backend.appliance", },
{'model': "backend.panel", },
{'model': "backend.register", },
{'model': "backend.program", },
{'model': "backend.acquisition", },
]
},
{
"name": _("Administration"),
"app_label": 'administration',
"items": [
{'model': "users.user", },
{'model': "auth.group", },
{'model': "constance.config", },
]
},
{
"name": _("Links"),
"app_label": 'links',
"items": [
{"name": "RQ Queues", "object_name": "django-rq", "link": "/django-rq/"},
{"name": "RQ Status", "object_name": "admin-rq", "link": "/admin/rq/"},
{"name": "API Index", "object_name": "api-index", "link": "/api/index/"},
{"name": "Resources Usage", "object_name": "resources-usage", "link": "/admin/resources_usage/"},
]
},
{
"name": _("Debug"),
"app_label": 'debug',
"items": [
{'model': "chat.room", },
{'model': "tasks.countbeanstask", },
{'model': "tasks.sendemailtask", },
]
},
]
def sidebar_config(request):
return BOOTSTRAP_ADMIN_SIDEBAR_MENU_ITEMS
Sample result:

Other minor changes:
- added a few classed to the rendered menu to allow styling
- added a new "user_tools_items" block to base.html for easier tools customization
hi @morlandi, I followed the steps but can't seem to get the custom sidebar to work.
I uninstalled the normal admin-bootstrap and installed yours with: sudo -H pip install https://github.com/douglasmiranda/django-admin-bootstrap/archive/master.zip
hi @morlandi, I followed the steps but can't seem to get the custom sidebar to work.
I uninstalled the normal admin-bootstrap and installed yours with: sudo -H pip install https://github.com/douglasmiranda/django-admin-bootstrap/archive/master.zip
Hi @mindfuucker ...
As the PR has not been merged into the main project, you should install from branch "feature/sidebar_config" of my fork, instead
Try this:
pip install git+https://github.com/morlandi/django-admin-bootstrap.git@feature/sidebar_config
@morlandi, Thank you for your assistance, It is working like a charm. Thank you!
@morlandi Thanks for contributing, I will review your code as soon as I'm free to do it.
@mindfuucker if you have any feedback on usage of this pull request, please share with us, it will help me to review this. =]
Hi @douglasmiranda , consider me at your disposal for any required adjustment. Thank you for sharing the project
this looked clean useful addition, any updates?