在Django模型上阻止任何CRUD功能 [英] Prevent any CRUD functionality on a django model
问题描述
Hello Im当前正在使用名为 django-river
的第三方程序包在我的应用程序中实现某种工作流系统。使用它的原因是因为它允许用户动态生成工作流并即时分配功能。我目前在需要该功能的某些模型中使用此功能。但是,有一种模式我希望限制这种自由。我不想允许用户添加任何实例,而不是我从一开始就添加的实例,或者对其进行编辑。
Hello Im currently using a third party package called django-river
to implement a sort of workflow system into my application. The reason for using this is because it allows the user to dynamically generate workflows and attatch functions on the fly . Im currently using this across some of my models that require this functionality. However , there is one model that i wish to restrict this freedom. I do not wish to allow the user to add any instances than the one i have added from the start , or edit them.
因此,我的问题是:
- 是否有一种方法可以实现django模型的这种锁定机制?
推荐答案
您可以管理数据库级权限 (谷歌如何为您的数据库实现它)。在django端添加多个数据库
与不同的用户,例如:
You can manage DB-level permissions (google how to implement it for your database). And in django side add multiple databases with different users, for e.g.:
A 用户-在默认设置下只能读取您的特殊表;
A user - can only read your spesific table, in default settings;
B 用户-拥有完全权限。
B user - has full permissions.
DATABASES = {
'default': {
'NAME': 'app_data',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'A',
'PASSWORD': 'qwerty'
},
'full': {
'NAME': 'app_data',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'B',
'PASSWORD': 'qwerty'
}
}
MyModel.objects.using('full').create(...)
MyModel.objects.create(...) # OperationError
或者您也可以在运行时更改用户。
这篇关于在Django模型上阻止任何CRUD功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!