class Task(models.Model):
class Meta:
permissions = (
("view_task", "Can see available tasks"),
("change_task_status", "Can change the status of tasks"),
("close_task", "Can remove a task by setting its status as closed"),
)
user.has_perm('app.view_task')
如果我有 contenttype.codename unknown(not hardcoded) 有什么方法可以检查权限,即它来自数据库动态如下
permission = Permission.objects.get(id=item.permission_id )
contenttype = ContentType.objects.get(id=permission.content_type_id)
user.has_perm(appname.contenttype.codename)
但它总是返回 false