在w管理中添加子菜单

时间:2019-11-06 15:18:39

标签: wagtail modeladmin

W是很棒的CMS。 我确实有一个问题,如何在管理员中添加子菜单。我有一个自定义模型Locations,在该模型中,我有2个外键。要管理通过Modeladmin创建的位置模型,请使用菜单。但是,要管理城市或外键内容,我还需要在modeladmin中创建。

我仅在modeladmin中看到一个选项,可将其添加到设置菜单。我在管理员中需要的是以下

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

目前,我只能通过menu_order = 200来确定顺序

有没有办法使w的导航具有导航功能?

2 个答案:

答案 0 :(得分:1)

您可以使用ModelAdminGroup将多个ModelAdmin视图分组为一个子菜单:

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)

答案 1 :(得分:0)

我找到了。

您可以使用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)