Different UserAdmin for different administrators in Django Admin

There are 2 users in my Django Admin app: admin which is superauser and editor which is staff:

  • admin can do everything,
  • editor has pemissions on blog application to be able to manage blog posts, categories, tags, etc.
  • editor has no pemission on auth application which means editor cannot manage users and permissions.

Now I would like to allow editor to be able to create new users with this restrictions:

  • editor can only manage users which are NOT superadmin or staff,
  • editor cannot even see superadmin or staff users,
  • when creating new user, editor should be able to set only active setting in Permissions area (superuser, staff, user permissions and groups should be either disabled or even better not shown).

How can I achieve this ?

One way would be to have 2 different User Admin pages:

  • standard/default User Admin page for my superadmin users,
  • customized User Admin page for my staff users.
    But I’m not sure if that is possible - when I tried to register different UserAdmin page I got error django.contrib.admin.sites.AlreadyRegistered: The model User is already registered with 'auth.UserAdmin'.

So what would you suggest ?

Thank you!

Yes, it is possible to do what you describe.

You’ve got a whole page in the docs at The Django admin site | Django documentation | Django that describe the options available within the ModeAdmin class.

For example, the get_queryset method lets you identify which objects are visible to a user. (See the example!) The get_list_display lets you dynamically define which fields get shown in the listing page, where get_fields lets you specify which fields are shown on the details page.

So it can be done - it’s up to you to decide if it’s worth it to you to define all these functions, or if you just want to create “staff-specific” views to edit those models and not try to wedge this functionality into the admin. (My opinion is that it’s going to be a lot easier in the long run to just create your own specific pages rather than jamming this into the admin. So my suggestion would be to create custom pages for this.)