我应该如何正确地为模型添加权限?

时间:2019-08-07 03:55:49

标签: django user-permissions django-permissions

当用户注册时,我添加了查看内容的权限。但是,添加的权限使用Django默认值进行分类。我想添加查看权限,但不知道如何。用户一旦获得此许可,便可以查看专门的内容。

class Viewing(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE) 
    view_content = models.BooleanField(default=False)
    order_id = models.CharField(max_length=250, blank=True)
    purchases = models.IntegerField(default = 0, blank=True)

    class Meta:
     ordering = ['user']
     permissions = (("view_content", "Content Access"),)


def __str__(self):
    return f'{self.user} ({self.view_content})'


django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
c(auth.E005) The permission codenamed 'view_content' clashes with a builtin permission for model 'mymodel.Viewing'.

如何删除,添加或检查此权限?这是我目前拥有的。

#Remove
remove_perm('view_content', user, Viewing)

#Check
 user.has_perm('mymodel.view_content')

#Added 
See model above

0 个答案:

没有答案