Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom urls #336

Open
jdenisTLM opened this issue Mar 31, 2024 · 1 comment
Open

Custom urls #336

jdenisTLM opened this issue Mar 31, 2024 · 1 comment

Comments

@jdenisTLM
Copy link
Contributor

jdenisTLM commented Mar 31, 2024

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) :

  • Activity menu item
  • ActivityCustom menu item

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
Copy link

cobia commented May 13, 2024

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.

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

No branches or pull requests

2 participants