django-admin-bootstrap icon indicating copy to clipboard operation
django-admin-bootstrap copied to clipboard

Allow sidebar customization

Open morlandi opened this issue 7 years ago • 6 comments

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

  1. add "BOOTSTRAP_ADMIN_SIDEBAR_MENU_CALLBACK" to project settings:

file "settings.py":

BOOTSTRAP_ADMIN_SIDEBAR_MENU_CALLBACK = 'admin_ex.sidebar.sidebar_config'
  1. 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:

sidebar_config

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

morlandi avatar Sep 06 '18 07:09 morlandi

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

FunDeckHermit avatar Oct 02 '18 14:10 FunDeckHermit

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 avatar Oct 02 '18 14:10 morlandi

@morlandi, Thank you for your assistance, It is working like a charm. Thank you!

FunDeckHermit avatar Oct 08 '18 09:10 FunDeckHermit

@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. =]

douglasmiranda avatar Oct 13 '18 19:10 douglasmiranda

Hi @douglasmiranda , consider me at your disposal for any required adjustment. Thank you for sharing the project

morlandi avatar Oct 15 '18 06:10 morlandi

this looked clean useful addition, any updates?

fopina avatar Feb 08 '20 13:02 fopina