【发布时间】:2015-10-13 10:41:13
【问题描述】:
我试图在迁移中创建自定义权限,但是运行迁移后,权限表中没有创建权限。有人能指出错误是什么吗? 此外,我不确定应该使用什么作为 ContentType 的相关模型,因为该权限用于限制可以查看显示网站上用户摘要的页面的用户。 任何帮助将不胜感激,谢谢。
def add_view_aggregated_data_permissions(apps, schema_editor):
ContentType = apps.get_model('django', 'ContentType')
Permission = apps.get_model('auth', 'Permission')
content_type = ContentType.objects.get(app_label='auth', model='user')
permission = Permission.objects.create(codename='can_view_data',
name='Can view data',
content_type=content_type)
【问题讨论】:
-
为什么要以这种方式创建权限?
-
这是错误的做法吗?我想为视图创建权限,我应该怎么做?
标签: django django-migrations django-permissions