开发者

How are permissions in Django created?

开发者 https://www.devze.com 2023-03-27 21:02 出处:网络
The following throws a DoesNotExist: exception: 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 开发者_StackOverflowI create this permission manually ?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消