How to hide-show menu in wagtail CMS:
Here is my code on register_admin_menu_item hook inside blog/wagtail_hooks.py
from wagtail.core import hooks
from wagtail.admin.menu import MenuItem
@hooks.register('register_admin_menu_item')
def register_custom_admin_menu_item():
return MenuItem(_('Site Admin'), reverse('admin_menu'), classnames='icon icon-folder-inverse',
order=20000)
For imposing the access on the menu, we can create the custom
MenuItem
Class and override theis_shown
method as below:Now use this
CustomAdminMenuItem
instead of MenuItem like:You can implement custom permission check also using
has_perm
inside is_shown like:For more details visit the source code here and doc here.