unfoldadmin / django-unfold

Modern Django admin theme for seamless interface development
https://unfoldadmin.com
MIT License
1.94k stars 188 forks source link

Set Applications & models sidebar configurations on AppConfig level #738

Closed An4ik closed 2 months ago

An4ik commented 2 months ago

Is it a third party application feature request? No

Describe your feature request in my django project i have a lot and lot of models and application and want the applications to be collapsable in sidebar. To achieve it i'm doing this:

"SIDEBAR": {
        ...
        "navigation": [
            {
                ...
                "collapsible": True,  # Collapsible group of links
                "items": [
                    {
                        "title": _("Users"),
                        "link": reverse_lazy("admin:users_user_changelist"),
                    },
                    {
                        "title": _("Groups"),
                        "link": reverse_lazy("admin:users_group_changelist"),
                    },
                ],
               ...
            },
        ],
    },

So since i probably need to add for every app & model, but need only set collapsible=True. and if we remove "SIDEBAR" attribute it will list all application & models by default, so i came up with the idea to add application sidebar setting in app level, probably it could be like this:

myproject/myapp/apps.py:

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _

class MyAppConfig(AppConfig):
    name = "my_app"
    verbose_name = _("My App")
    sidebar = {
        'collapsable': true',
        'icon':  ..., 
         ...  # any other setting may be added here.
    }    

then we will need to get that config on UnfoldAdminSite or other places, have not digging deeper yet, but i can implement it , if you will agree and give green light for it.

thanks.

BTW great tool, just switched to it from using grappelli admin

lukasvinclav commented 2 months ago

I think you can write a simple function here which will go through the list of dicts and adds collapsible key if it is missing.