[Django]-Django – Is there any way to hide superusers from the user list?

6👍

You can override get_queryset method of User Admin and only return results based on logged in user:

myapp/admin.py

from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

@admin.register(User)
class UserAdmin(BaseUserAdmin):
    def get_queryset(self, request):
        qs = super(UserAdmin, self).get_queryset(request)
        if not request.user.is_superuser:
            return qs.filter(is_superuser=False)
        return qs

Leave a comment