Search code examples
djangodjango-admindjango-admin-actions

How to change admin color in Django based on whether person is an Superuser or not?


I would like to implement a function in Django admin, that if a person logged is superuser then the color in admin is different. How can I approach it?

I don't want 'normal' users to have access to admin, but I want to have 2 levels of access - superuser that can change everything (and add more personnel etc) and normal staff level, who can't add other employees and is limited in what he can do.

How can I approach the issue?

Can I simply add flag somewhere which states that if logged user is superuser then use different/additional css or something?


Solution

  • You can use the is_superuser check on the User object to determine if the user is a superuser or not a superuser.

    Below is a sample code that you can use in your HTML

    {% if request.user.is_superuser %}
    
    <!---Add color code for admin--->
    
    {% else %}
    
    <!---Add color code for other users---->
    
    {% endif %}