Wagtail为MyPage设置其他权限 [英] Wagtail set additional permissions for MyPage

查看:140
本文介绍了Wagtail为MyPage设置其他权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W新手.

我正在尝试为特定模型添加一些其他权限,但是"wa管理"中没有任何显示.我可以用"django"方式做到这一点,但我有一种印象,即w可以处理这种类型的权限.我在wagtail文档中找不到任何提示.

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.

我有一个名为"MyPage"的新模型:

I have a new model named "MyPage":

class MyPage(Page):
    [...]

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

如何在Wagtail管理员的网上论坛"部分中提供此权限?

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

推荐答案

原来,有一个w子钩子可以执行以下操作:"register_permsissions".

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

如果应用程序中不存在名为"wagtail_hooks.py"的文件,请输入以下内容:

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".

这篇关于Wagtail为MyPage设置其他权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆