Jake Mulhern
Jake Mulhern

Reputation: 772

How to set is_staff to True in Django when a user is created with a specific group selected

How would I automatically set is_staff to True when creating a new user in the Django admin when they have a specific group selected?

Upvotes: 0

Views: 929

Answers (1)

user12065892
user12065892

Reputation:

The best way to achieve it using the django signal.

Just listen when a user created or updated its group. when it is created or updated with the specific group selected, You just set is_staff=True and save it.

To learn more about Django signal: https://docs.djangoproject.com/en/3.2/topics/signals/

Learn more about Django group and permission https://docs.djangoproject.com/en/3.2/ref/contrib/auth/#django.contrib.auth.models.User.groups

Upvotes: 1

Related Questions