Django 用户“每个项目”小组分配
这是我的问题:我的网站有用户,他们可以创建项目并访问其他用户的项目。 每个项目可以为用户分配不同的权限。
因此,我可以拥有项目 A:用户“John”位于组“manager”中,项目“B”用户“John”位于组“worker”中。
我如何使用 Django 用户身份验证模型来做到这一点?
从 SQL 的角度来看,我希望能够在“auth_user_groups”表的主键中添加“project_id”。
我认为个人资料在这里没有任何帮助。有什么建议吗?
更新:“工人”和“经理”只是我的应用程序定义的权限组(或“角色”)的两个示例。未来还会有更多。例如:我可能还会有“管理”、“报告”等...
Here's my problem : my site has users, which can create projects, and access other user's projects.
Each project can assign different rights to users.
So, i could have Project A : user "John" is in group "manager" , and Project "B" user "John" is in group "worker".
How could I use the Django User authentication model to do that ?
From a SQL point a view, what i would like is to be able to add "project_id" in the primary key for the "auth_user_groups" table.
I don't think profile is of any help here. Any advice ?
UPDATE : "worker" and "manager" are just two examples of the permission group (or "roles") that my application defines. There will be more in the future. Eg : i will probably also have "admin", "reporting", etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确实在组中需要这些信息,我认为最好的解决方案是对必要的模型进行子类化,并从中创建您自己的身份验证应用程序/身份验证后端!
我不知道是否有必要将项目与组相关联,您还可以创建一个与用户具有 1:1 关系且与项目具有 1:1 关系的用户配置文件,因此您可以将项目分配给用户,然后签入您的应用程序 用户与哪些项目相关?
我想到的第三个解决方案是拥有一个模型,其中一个外键用于项目,一个外键用于分组,这可能也适合您,但可能没有很好的可用性!
最肮脏的方法可能是使用猴子修补(add_to_class)将外键添加到组中,但我想只有当您找不到另一种下降方法来做到这一点时才推荐这样做,并且在某种程度上是您的最后手段,但不是首选!
If you really need this information in the groups i think the best solution is to sub class the necessary models and make your own auth application/auth backend out of this!
I dont know if it's necessary to relate the projects to groups, you could also create an user profile that has a 1:1 relation to the user and a m:n to projects, so you could assign projects to a user and then check in your apps what projects the user is related to?
Third solution that comes to my mind would be having a model with one foreignkey to project and one to group, which might also work for you, but probably has no good usability!
The dirtiest way would probably be to add a foreignkey to group using monkey-patching (add_to_class), but i guess this only recommendable if you don't find another descent way to do it and is somehow your last resort, but not first choice!
如果您可以在用户模型中没有它并且可以拥有关联的用户配置文件模型,那么像这样的东西怎么样:
If you can live without it in your User model and can have it an associated user profile model, how about something like: