[Answered ]-How Django rest IsAdminUser does not pass even the user is admin?

1👍

The problem is that you defined your Admin model from a regular Django model so Django cannot find the user permissions associated to it.

You should inherit from a Django authentication user model (AbstractUser or AbstractBaseUser) as indicated in the documentation.

For instance, you can do:

from django.contrib.auth.models import AbstractUser

class CustomAdminUser(AbstractUser):
    # Here you normally only want to 
    # define the fields not defined in 
    # the base model AbstractUser
    pass 

Then, to create your admin:

CustomAdminUser.objects.create_superuser(...)

Last but not least, two important things (mentioned in the above Django documentation’s link):

  • Don’t forget to point the AUTH_USER_MODEL to your custom user model. Do this before creating any migrations or running manage.py migrate for the first time.
  • Register the model in the app’s admin.py.

Leave a comment