我正在努力扩展w ,,我正在使用下一个钩子:
python
@hooks.register('register_settings_menu_item')
def register_django_admin_menu_item():
return MenuItem(_('Site Admin'), '/django-admin', classnames='icon icon-wagtail-inverse', order=20000)
我获得了django管理页面的链接,但我想将该项目仅限于具有员工权限的用户。
我该怎么做?
答案 0 :(得分:4)
试试这个:
class CustomAdminMenuItem(MenuItem):
def is_shown(self, request):
return request.user.is_staff
@hooks.register('register_admin_menu_item')
def register_custom_admin_menu_item():
return CustomAdminMenuItem(_('Site Admin'), reverse('admin_menu'), classnames='icon icon-folder-inverse', order=20000)
答案 1 :(得分:-1)
有一个装饰者:
from django.contrib.admin.views.decorators import staff_member_required
@staff_member_required
@hooks.register('register_settings_menu_item')
def register_django_admin_menu_item():
return MenuItem(_('Site Admin'), '/django-admin', classnames='icon icon-wagtail-inverse', order=20000)