Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add submenu's in wagtail admin

Wagtail is wonderfull CMS. I do have a question how to add submenu's in the admin. I got a custom model Locations in that model I got 2 foreignkeys. To manage the locations model in created via modeladmin a menu. However to manage the city's or foreignkey content I also need to create in modeladmin.

I only see an option in modeladmin to add the item to the settings menu. What I need in my admin is the following

+ pages
++ ...
+ locations
++ locations
++ cities
++ tags
+ ...

Currently I only can determine the order via the menu_order=200

Is there a way to make the navigation in wagtail have sub nav

like image 603
Enquest Avatar asked Sep 15 '25 07:09

Enquest


2 Answers

You can use ModelAdminGroup to group several ModelAdmin views into a submenu:

http://docs.wagtail.io/en/stable/reference/contrib/modeladmin/index.html#a-more-complicated-example

from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup, modeladmin_register

class LocationGroup(ModelAdminGroup):
    menu_label = 'Locations'
    items = (LocationAdmin, CityAdmin, TagAdmin)

modeladmin_register(LocationGroup)
like image 122
gasman Avatar answered Sep 18 '25 10:09

gasman


Ah I found it.

You can use ModelAdminGroup

https://docs.wagtail.io/en/v2.7/reference/contrib/modeladmin/index.html#summary-of-features

    menu_label = 'Library'
    menu_icon = 'folder-open-inverse'  # change as required
    menu_order = 200  # will put in 3rd place (000 being 1st, 100 2nd)
    items = (BookAdmin, AuthorAdmin, GenreAdmin)

# When using a ModelAdminGroup class to group several ModelAdmin classes together,
# you only need to register the ModelAdminGroup class with Wagtail:
modeladmin_register(LibraryGroup)
like image 44
Enquest Avatar answered Sep 18 '25 10:09

Enquest