Remove Authentication, Token, Python Social Auth from Django Admin

Gerry Sabar
2 min readAug 10, 2019

--

Default Django admin page

Often we don’t want to add unnecessary model in admin page when we include other party packages for our Django app. In this article we will cover how to remove from admin page Authentication and Authorization from django.contrib.auth, then Auth Token from djangorestframework-simplejwt package and last Python Social Auth from social-auth-app-django package.

Basically if you want to remove any unnecessary model from admin what you really need is finding the related model and using this command:


admin.site.unregister(PUT_MODEL_HERE)

admin.site.unregister itself is imported from this:

from django.contrib import admin

Remove Authentication and Authorization From Admin Page

This case is to remove Groups & Users from Authentication and Authorization section. Open urls.py from your Django project folder and add this line:

from django.contrib import admin
from django.contrib.auth.models import User, Group

Next add this line:

admin.site.unregister(User)
admin.site.unregister(Group)

If you refresh the page you can see now Authentication and Authorization section has gone from Django admin page. Please take a note for User that this method is works if you don’t override User model. If you already override default Django user then you just simple don’t need to register it to admin.

Remove Auth Token From Admin Page

If you install simplejwt package to implement jwt token in your Django REST application and need to get rid the Auth Token from admin page, you need to add this in urls.py:

from django.contrib import admin
from rest_framework.authtoken.models import Token

Then remove it from Django admin page:

admin.site.unregister(Token)

Remove Python Social Auth From Admin Page

If you install social-auth-app-django and need to remove Python Social Auth from Django admi page, you need to add this in urls.py:

from django.contrib import admin
from social_django.models import Association, Nonce, UserSocialAuth

Then remove it from Django admin page:

admin.site.unregister(Association)
admin.site.unregister(Nonce)
admin.site.unregister(UserSocialAuth)

The same principle goes to another 3rd party library if you want to remove it from admin. You need to find the models they use then using unregister method.

--

--

Responses (1)