Django组和权限。扩展群体拥有FK? [英] Django Groups and Permissions. Extending Groups to have a FK?

查看:119
本文介绍了Django组和权限。扩展群体拥有FK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种允许不同学校在线管理其内容的产品。

I'm working on a product that allows different schools to administer their content online.

其中一部分涉及设置一个我自己编写的基于角色的访问控制逻辑。基本上,每所学校都有自己的一套角色,拥有自己的一套权限。软件的用户可以在任何给定的时间属于具有不同角色的多学校。

Part of this involves setting up a role based access control logic which I've written myself. Essentially, each school has its own set of roles that have their own set of permissions. A user of the software could belong to mulitple schools with differing roles at any given time.

由于种种原因,我想把这个改为Django的组和权限使用图书馆,如 django-guardian 。我正在面对的问题是我应该如何扩展团体模式,以便我可以在每个新学校中添加一个外键,还可以在Django中使用帮助方法,还可以使用django-guardian这样的库。

For various reasons, I want to ditch this and instead use Django's Groups and Permissions together with a library like django-guardian. The problem that I am facing is how should I go about extending the Groups model such that I can include a Foreign Key to each new school and still be able to use the helper methods in Django and also libraries like django-guardian.

我想出的一个可能的方法是简单地创建基于事件名称的组,如School 1 - Admin,School 1 - Teacher,School 2 - 管理员,学校2 - 教师和基于此的查询权限。有没有一个很好的理由为什么我不应该这样做?

One possibly approach I came up with is to simply create groups based on event names such as 'School 1 - Admin', 'School 1 - Teacher', 'School 2 - Admin', 'School 2 - Teacher' and query permissions based on this instead. Is there a good reason why I shouldn't do it this way?

推荐答案

仔细检查后,django-guardian能够解决我的需要。我在这里写了关于我的完整实现:​​ http://pragmaticstartup.wordpress.com/2012/06/26/django-guardian-a-full-access-control-logic-acl-example/

Upon closer inspection, django-guardian was able to solve my needs. I wrote about my full implementation here: http://pragmaticstartup.wordpress.com/2012/06/26/django-guardian-a-full-access-control-logic-acl-example/

这篇关于Django组和权限。扩展群体拥有FK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆