Wagtail set additional permissions for MyPage

江枫思渺然 提交于 2019-12-10 19:47:12

问题


Wagtail newbie here.

I am trying to add some additional permissions to specific models, but nothing shows up into the "wagtail admin". I can do this the "django" way but I have the impression that wagtail could handle this type of permissions. I could not find any hints in the wagtail documentation.

I have a new model named "MyPage":

class MyPage(Page):
    [...]

    class Meta:
        permissions = (
        ('view_restricted_document', 'can view restricted documents'),
    )

How do I make this permission available in the groups section of the wagtail admin?


回答1:


It turns out that there is a wagtail hook which does just that: "register_permsissions".

Create a file named "wagtail_hooks.py" if it does not exist in your app and enter the following:

from wagtail.wagtailcore import hooks
from django.contrib.auth.models import Permission

@hooks.register('register_permissions')
def view_restricted_page():
    return Permission.objects.filter(codename="view_restricted_document")

That's it. Now if I browse the groups section, under "Other Permissions" I can view the additional option "can view restricted document".



来源:https://stackoverflow.com/questions/37663893/wagtail-set-additional-permissions-for-mypage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!