0

以下引发DoesNotExist:异常:

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

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

4

1 回答 1

3

是的你应该

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
于 2011-08-12T15:21:22.697 回答