djangowagtailwagtail-admin

Add menu items in wagtail ModelAdminGroup


I want to add non ModelAdmin items in a ModelAdminGroup as for example a MenuItem, like this:

MenuItem('A title', '/some_url/', icon_name='doc-full-inverse', order=1)

But I could not found any hints neither in Wagtail documentation nor on stackoverflow.

My ModelAdminGroup looks like this

class MyModelAdminGroup(ModelAdminGroup):
    menu_label = "Some stuff"
    menu_icon = "fa-suitcase"
    menu_order = 1
    items = (Model1Admin, Model2Admin)

I try to do this:

class MyModelAdminGroup(ModelAdminGroup):
    menu_label = "Some stuff"
    menu_icon = "fa-suitcase"
    menu_order = 1
    items = (Model1Admin, Model2Admin, MenuItem('A title', '/some_url/', icon_name='doc-full-inverse', order=1))

And some other idiotic stuff

But all I try crashed ...

I finally found an easy solution. I just write it bellow just in case it could help the community other people


Solution

  • I finally came with a trivial solution: just extending my custom ModelAdminGroup class and writing a specific get_submenu_items method:

    class MyModelAdminGroup(ModelAdminGroup):
        menu_label = "Some stuff"
        menu_icon = "fa-suitcase"
        menu_order = 1
        items = (Model1Admin, Model2Admin)
    
        def get_submenu_items(self):
            menu_items = super().get_submenu_items()
            menu_items.append(MenuItem('A title', '/some_url/', icon_name='doc-full-inverse', order=1))
            return menu_items