Django 中的权限是如何创建的?

发布于 2024-11-29 09:20:27 字数 193 浏览 0 评论 0原文

以下代码引发 DoesNotExist: 异常:

from django.contrib.auth.models import Permission
Permission.objects.get(codename='add_eventmanager')

我应该手动创建此权限吗?

The following throws a DoesNotExist: exception:

from django.contrib.auth.models import Permission
Permission.objects.get(codename='add_eventmanager')

Should I create this permission manually ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装迷糊 2024-12-06 09:20:27

是的,你应该

ROLE_PERMS =  (
    ('manage_managers', 'Manage managers'),
    ('manage_roles', 'Manage roles'),
    ('manage_enterprise_config', 'Manage enterprise config'),
    ('manage_orga_imports', 'Manage organization imports'),
    ('consult_stats', 'Consult statistics'),
    ('manage_distribs', 'Manage distributions'),
    ('manage_docs', 'Manage documents'),
    ('consult_docs', 'Consult documents'),
    ('manage_employees', 'Manage employees'),
    ('consult_employees', 'Consult employees'),
    ('manage_employee_imports', 'Manage employee imports'),
    ('manage_settings', 'Manage settings'), )

class Role(models.Model):

    class Meta:
        ordering = ['name']
        verbose_name = _('role')
        verbose_name_plural = _('roles')
        permissions = ROLE_PERMS

Yes you should

ROLE_PERMS =  (
    ('manage_managers', 'Manage managers'),
    ('manage_roles', 'Manage roles'),
    ('manage_enterprise_config', 'Manage enterprise config'),
    ('manage_orga_imports', 'Manage organization imports'),
    ('consult_stats', 'Consult statistics'),
    ('manage_distribs', 'Manage distributions'),
    ('manage_docs', 'Manage documents'),
    ('consult_docs', 'Consult documents'),
    ('manage_employees', 'Manage employees'),
    ('consult_employees', 'Consult employees'),
    ('manage_employee_imports', 'Manage employee imports'),
    ('manage_settings', 'Manage settings'), )

class Role(models.Model):

    class Meta:
        ordering = ['name']
        verbose_name = _('role')
        verbose_name_plural = _('roles')
        permissions = ROLE_PERMS
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文