扩展特定用户组的django权限

时间:2018-03-26 06:56:00

标签: django

我有两种模式:

class Coach(User):
    name = models.CharField()
    email = models.EmailField()
    branding = models.CharField(choices=BRANDINGS)

class Patient(User):
    name = models.CharField()
    email = models.EmailField()
    branding = models.CharField(choices=BRANDINGS)

有没有办法让教练只看病人的品牌?我认为在每个视图上编写过滤器查询集是个坏主意。 Mayby可以通过更改权限来完成吗?

1 个答案:

答案 0 :(得分:0)

为什么不建立教练与病人的关系?

它看起来像这样:

class Coach(User):
    name = models.CharField()
    email = models.EmailField()
    branding = models.CharField(choices=BRANDINGS)

class Patient(User):
    name = models.CharField()
    email = models.EmailField()
    coach = model.ForignKey(Coach, related_name='Patient')

通过这种方式,只需添加视图choach.patient.all()搜索即可查找某位教练的所有患者