Django admin is_staff基于组 [英] Django admin is_staff based on group

查看:117
本文介绍了Django admin is_staff基于组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过选择组来选择is_staff?假设有两个组:用户,管理员

Is it possible to have is_staff selected by choosing a group? Let's say there are two groups: users, admins

当新用户位于用户组中时,他不是工作人员,但如果在管理员组中,则他是工作人员

When a new user is in the users group he is not staff, but if he is in the admins group he is staff.

推荐答案

我设法通过扩展UserAdmin类使其起作用,并在mascot6699的答案的帮助下将其放置在get_form函数中:

I managed to make it work by extending the UserAdmin class and in the get_form function I placed this with help of mascot6699's answer:

if obj.groups.filter(name="Administrator").exists():
    obj.is_staff = True
else:
    obj.is_staff = False

所以无论何时我放置管理员组中的用户(具有admin菜单)将选中is_staff选项,否则将取消选中它。

So whenever I place a user (with the admin menu) in the Administrator group it will check the is_staff option else it unchecks it.

这篇关于Django admin is_staff基于组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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