当我创建模型时:
class Info(models.Model):
name = models.CharField(max_length=26)
detail = models.CharField(max_length=16)
class Meta:
permissions = (
("add_info", "Can view info"), # C
("read_info", "Can view info"), # R
("update_info", "Can update info"), # U
("delete_info", "Can delete info") # D
)
当我制作色彩时,却出现了错误:
app07.Info: (auth.E005) The permission codenamed 'add_info' clashes with a builtin permission for model 'app07.Info'.
app07.Info: (auth.E005) The permission codenamed 'delete_info' clashes with a builtin permission for model 'app07.Info'.
因此,当我创建用户时,模型将自动创建权限。但是你看,READ
和UPDATE
权限不是read_info
和update_info
,那么模型的默认权限是什么?
答案 0 :(得分:0)
默认权限
当您的INSTALLED_APPS设置中列出了django.contrib.auth时,它将确保为您安装的某个应用程序中定义的每个Django模型创建三个默认权限 - 添加,更改和删除。
假设您有一个app_label foo和名为Bar的模型的应用程序,要测试您应该使用的基本权限:
add: user.has_perm('foo.add_bar')
change: user.has_perm('foo.change_bar')
delete: user.has_perm('foo.delete_bar')