I know how permissions/groups/user work together in a "normal" way. However, I feel incomfortable with this way to do in my case, let me explain why.
我知道权限/组/用户如何以“正常”方式一起工作。但是,在我的情况下,我觉得这样做是不舒服的,让我解释一下原因。
In my Django models, all my users are extended with models like "Landlord" or "Tenant".
在我的Django模型中,我的所有用户都扩展了“Landlord”或“Tenant”等模型。
Every landlord will have the same permissions, every tenant will have other same permissions.. So it seems to me there is not interest to handle permission in a "user per user" way.
每个房东都有相同的权限,每个租户都有其他相同的权限..所以在我看来,没有兴趣以“每用户一个用户”的方式处理权限。
What I'd like to do is link the my Tenant and Landlord models (not the instances) to lists of permissions (or groups).
我想做的是将我的租户和房东模型(不是实例)链接到权限(或组)列表。
Is there a way to do this? Am I missing something in my modelisation? How would you do that?
有没有办法做到这一点?我在模型化中遗漏了什么吗?你会怎么做?
1 个解决方案
#1
1
django.contrib.auth
has groups and group permissions, so all you have to do is to define landlords
and tenants
groups with the appropriate permissions then on your models's save()
method (or using signals or else) add your Landlord
and Tenant
instances to their respective groups.
django.contrib.auth具有组和组权限,因此您所要做的就是使用适当的权限定义房东和租户组,然后在模型的save()方法上(或使用信号或其他)将Landlord和Tenant实例添加到他们各自的团体。
#1
1
django.contrib.auth
has groups and group permissions, so all you have to do is to define landlords
and tenants
groups with the appropriate permissions then on your models's save()
method (or using signals or else) add your Landlord
and Tenant
instances to their respective groups.
django.contrib.auth具有组和组权限,因此您所要做的就是使用适当的权限定义房东和租户组,然后在模型的save()方法上(或使用信号或其他)将Landlord和Tenant实例添加到他们各自的团体。