Skip to content
Advertisement

Django admin is_staff based on group

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.

Advertisement

Answer

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

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement