Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Allow sidebar customization #128

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

morlandi
Copy link

@morlandi morlandi commented Sep 6, 2018

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

@FunDeckHermit
Copy link
Contributor

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

@morlandi
Copy link
Author

morlandi commented Oct 2, 2018

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

@FunDeckHermit
Copy link
Contributor

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

@douglasmiranda
Copy link
Owner

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

@morlandi
Copy link
Author

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

@fopina
Copy link

fopina commented Feb 8, 2020

this looked clean useful addition, any updates?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants