有权修改Django Admin中模型的一个字段的用户 [英] User with permission to modify only one field of the model in the Django Admin
问题描述
我有一个名为 ExpertUser 的用户,该用户只能修改Django Admin中用户的被调用模型(货币)的属性.
我尝试使用 Meta 在模型中添加权限,但是使用该权限输入我无法修改任何东西,因为我无权访问任何用户./p>
我的模特是这样的
class Client(models.Model):用户= models.OneToOneField(用户,on_delete = models.CASCADE)money = models.FloatField(默认= 1000)def __str __():返回self.user.username类Meta:权限=((" can_view_money,"可以查看资金),)
看看Django Guardian.这样在分配各个级别的权限时提供了更大的灵活性.Django仅允许您在对象级别设置权限,因此在您的情况下,您只能设置创建/编辑/删除客户端对象的权限.
http://django-guardian.readthedocs.io/en/v1.4.8/index.html
如果这还不够的话,还有其他一些具有所需功能的软件包:
https://djangopackages.org/grids/g/perms/ >
I have a user named ExpertUser who should only be able to modify an attribute of the called model (money) of the users in the Django Admin.
I have tried adding permissions in the model using the Meta but when entering with that permission I can not modify anything since I do not have access to any user.
My model is this:
class Client(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
money = models.FloatField(default=1000)
def __str__(self):
return self.user.username
class Meta:
permissions = (("can_view_money", "Can view money"),)
Have a look at Django Guardian. That provides more flexibility in assigning permissions on various levels. Django only lets you set permissions at object level, so in your case you were only able to set permission to create/edit/delete Client objects.
http://django-guardian.readthedocs.io/en/v1.4.8/index.html
If that doesn't suffice, there are a few other packages with the desired functionality:
https://djangopackages.org/grids/g/perms/
这篇关于有权修改Django Admin中模型的一个字段的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!