unfoldadmin / django-unfold

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

Custom urls #336

Open jdenisTLM opened 1 month ago

jdenisTLM commented 1 month ago

I'm playing with custom urls to add a custom view to my ModelAdmin. This works, except one little thing.

Here is my context :

I've got an ActivityAdmin

@admin.register(Activity)
class ActivityAdmin(ModelAdmin):

I've got a custom url, with admin/activity/custom url :

    custom_urls = [
        ("custom/", "management_activity_custom", ActivityCustomAdminView.as_view())
    ]

This brings to this situation : when i navigate to admin/activity/custom, both menu items in sidebar are active (css color for active link) :

That could sounds logic, because, when we enter on admin/activity/add for exemple, we have to keep the activity link active in the sidebar for the activity menu item.

How can I do to have only my custom view active in the sidebar menu ?

cobia commented 1 day ago

I solved this problem by attaching a querystring parameter to the url in the sidebar menu. So if you do something like:

"link": lambda url: f'{reverse_lazy("admin:my_model_add")}?always_inactive=true',

Might not be the best and long term way, but works for now.