Django:向特定模型实例添加权限
我正在寻找实现用户权限以允许用户编辑特定模型实例的最佳方法。
例如,我有这样两个模型:
model RadioChannel(models.Model):
name = models.CharField(max_length=150, unique= True)
number = models.IntegerField( unique= True)
model ProgramSchedule(models.Model):
channel = models.ForeignKey("RadioChannel")
name = models.CharField(max_length=150, unique= True)
start_time = models.DateTimeField()
现在我的操作员是我的内置 Django 用户。我想为这些用户创建组,以便他们只能添加/删除/编辑允许的 ProgramSchedules。此外,我想将这些用户的组添加到管理面板。
谢谢。
I am looking for the best way to implement user permissions to allow users to edit specific model instances.
For instance, I have such two models:
model RadioChannel(models.Model):
name = models.CharField(max_length=150, unique= True)
number = models.IntegerField( unique= True)
model ProgramSchedule(models.Model):
channel = models.ForeignKey("RadioChannel")
name = models.CharField(max_length=150, unique= True)
start_time = models.DateTimeField()
Now my Operators are my build-in Django users. I want to make groups for these users so that they can only add/remove/edit ProgramSchedules that are allowed. In addition I want to add groups to these users to the admin panel.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找对象权限实现。一个很好的比较在这里:
http://djangopackages.com/grids/g/perms/
无耻插件:
这是我的一个非常流行的每对象权限应用程序的分支: http://github.com/azizmb/django-authority
You are looking for an object permission implementation. A good comparison is here:
http://djangopackages.com/grids/g/perms/
Shameless plug:
Heres my fork of a very popular per-object permission app: http://github.com/azizmb/django-authority
如果我的理解是正确的,那么您需要实现的就是 Django 中的行级权限。看看这个是否有帮助。 http://code.djangoproject.com/wiki/RowLevelPermissionsDeveloper
If I am getting you correct, what you need to implement is called row level permissions in Django. Have a look at this if it helps. http://code.djangoproject.com/wiki/RowLevelPermissionsDeveloper
我建议使用 Django Guardian 来获取对象级权限。
I would recommend using Django Guardian for object-level permissions.