Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the sidebar from Wagtail?

Tags:

django

wagtail

I'm following the Wagtail docs to create a navigation, but it's recommend to use based on 'Snippets', so I would like to change the sidebar to show "Navigation" or "Menu" instead of 'Snippets', is that possible? enter image description here

But when I use just like the docs recommends for sidebar changes:

sidebar_content_panels = [
    SnippetChooserPanel('advert', Advert),
    InlinePanel('related_links', label="Related links"),
]

So it raises a AttributeError: enter image description here

like image 621
Max Ferreira Avatar asked Aug 05 '15 02:08

Max Ferreira


2 Answers

The sidebar_content_panels code is not relevant here - it demonstrates how you would add an extra tab to the page editor, if your pages contained "main content" and "sidebar content" that you wanted to keep separate. It's nothing to do with the sidebar menu in the Wagtail admin.

It's possible to add new items to the admin menu using the register_admin_menu_item hook (http://docs.wagtail.io/en/v1.0/reference/hooks.html#register-admin-menu-item), but this doesn't support editing an existing item, so it won't be possible to change the label of the 'snippets' menu. However, you could look at the 'wagtailmodeladmin' package https://github.com/ababic/wagtailmodeladmin - this allows you to set up admin areas that work like the snippet editor, but exist at the top level of the menu.

like image 170
gasman Avatar answered Oct 23 '22 01:10

gasman


I dont know if it was at the time, but now you can change the name of the sidebar navigation without the need to move to ModelAdmin. This is done by using the "construct_main_menu" hook and by adding the snippet below to model admin like so:

@hooks.register("construct_main_menu")
def change_snippet_name(request, menu_items):
    for item in menu_items:
        if item.__class__.__name__ == "SnippetsMenuItem":
            item.label = "Contact persons"
like image 33
Andreas Avatar answered Oct 23 '22 03:10

Andreas