Django Admin - Giving staff members access to certain areas by default

11.8k views Asked by At

Could anyone tell me how to give staff users in django (those with is_staff set to true) access to some models by default in the admin interface? Currently if I log in as a staff member I just get "You don't have permission to edit anything". If I log in as a super user I get access to several things (those registered in admin.py).

I'd like to basically treat staff members as a group and allow them to edit a selection of models, or to set some permissions as defaults. I have searched around the documentation to no avail.

5

There are 5 answers

2
dan-klasson On BEST ANSWER

You can create a group and make new staff users members in it. Not giving permissions by default is a security feature.

0
George Cummins On

Add admin.autodiscover() to the project urls.py files.

0
emispowder On

Have you written a custom authentication backend? I had written one to use LDAP to interface with an existing authentication system and was having the same issue as you with "staff" users not having perms to any of the models. Super users were fine, just staff problematic.

I fixed this by superclassing ModelBackend in my custom auth class:

## in my custom auth.py
from django.contrib.auth.backends import ModelBackend

class ActiveDirectoryBackend(ModelBackend):

The ModelBackend class has functions that are required for figuring out group and user level permissions.

This fixed users marked as "staff" from not being able to access models and allowed me to control access to different models via groups and permissions.

0
Super Kai - Kazuya Ito On

You can group staff members to give them permissions.

First, check Active and Staff status then click on ➕ to create a group as shown below. *Both Active and Staff status must be checked otherwise the user cannot log in Django Admin:

enter image description here

Then, select some permissions from the left box and move them to right box then click on SAVE as shown below:

enter image description here

Then, Normal staff is added to the right box as shown below:

enter image description here

Then, scroll down to the bottom then click on SAVE:

enter image description here

Now, the user can log in then can do something permitted as shown below:

enter image description here

1
unlockme On

To do this, create a group in Groups in the django admin. Django Admin creating a group with permissions

You can add model permissions according to the models you would wish the staff or users to have access to.

Once that is done, add your your users to that group. You do that by selecting the user of interest and adding them to the created groups. Add specific user to groups

Once this is done, that user will have access to all those models the Group has permissions on.