You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a custom "submenu", just like current "settings_menu" which appears in "main menu". Let's call it "Sales". I've done that because i need some menu container for additional installable "django-wagtail" apps which will automatically register in this "submenu". Currently i can only register ModelAdmin to "main menu" or using "add_to_settings_menu" property add it to "settings menu"
but there is no possibility to easily register using different menu construction hook because in WagtailRegisterable source code there is something like:
So the whole "WagtailRegisterable" could look like this:
classWagtailRegisterable:
""" Base class, providing a more convenient way for ModelAdmin or ModelAdminGroup instances to be registered with Wagtail's admin area. """add_to_settings_menu=Falseexclude_from_explorer=Falsemenu_hook=Nonedefregister_with_wagtail(self):
@hooks.register('register_permissions')defregister_permissions():
returnself.get_permissions_for_registration()
@hooks.register('register_admin_urls')defregister_admin_urls():
returnself.get_admin_urls_for_registration()
ifmenu_hookisNone:
menu_hook= (
'register_settings_menu_item'ifself.add_to_settings_menuelse'register_admin_menu_item'
)
@hooks.register(menu_hook)defregister_admin_menu_item():
returnself.get_menu_item()
# Overriding the explorer page queryset is a somewhat 'niche' / experimental# operation, so only attach that hook if we specifically opt into it# by returning True from will_modify_explorer_page_querysetifself.will_modify_explorer_page_queryset():
@hooks.register('construct_explorer_page_queryset')defconstruct_explorer_page_queryset(parent_page, queryset, request):
returnself.modify_explorer_page_queryset(
parent_page, queryset, request)
defwill_modify_explorer_page_queryset(self):
returnFalse
classWagtailRegisterable:
""" Base class, providing a more convenient way for ModelAdmin or ModelAdminGroup instances to be registered with Wagtail's admin area. """add_to_settings_menu=Falseexclude_from_explorer=Falsedefregister_with_wagtail(self, menu_hook=None):
@hooks.register('register_permissions')defregister_permissions():
returnself.get_permissions_for_registration()
@hooks.register('register_admin_urls')defregister_admin_urls():
returnself.get_admin_urls_for_registration()
ifmenu_hookisNone:
menu_hook= (
'register_settings_menu_item'ifself.add_to_settings_menuelse'register_admin_menu_item'
)
@hooks.register(menu_hook)defregister_admin_menu_item():
returnself.get_menu_item()
# Overriding the explorer page queryset is a somewhat 'niche' / experimental# operation, so only attach that hook if we specifically opt into it# by returning True from will_modify_explorer_page_querysetifself.will_modify_explorer_page_queryset():
@hooks.register('construct_explorer_page_queryset')defconstruct_explorer_page_queryset(parent_page, queryset, request):
returnself.modify_explorer_page_queryset(
parent_page, queryset, request)
defwill_modify_explorer_page_queryset(self):
returnFalse
Issue Summary
I have created a custom "submenu", just like current "settings_menu" which appears in "main menu". Let's call it "Sales". I've done that because i need some menu container for additional installable "django-wagtail" apps which will automatically register in this "submenu". Currently i can only register ModelAdmin to "main menu" or using "add_to_settings_menu" property add it to "settings menu"
Steps to Reproduce
I have an ExampleModelAdmin
this is how to register to main menu:
this is how to register to settings menu
but there is no possibility to easily register using different menu construction hook because in WagtailRegisterable source code there is something like:
wagtail/contrib/modeladmin/options.py
It would solve the problem if
menu_hook
can be accessed as a ModelAdmin property. For now it's hardcoded just for these values:So the whole "WagtailRegisterable" could look like this:
and the registration:
alternatively:
and registration:
Technical details
The text was updated successfully, but these errors were encountered: