0

Hi I am trying to create a superuser, however, after I added my own ProfileManager I get the error:

AttributeError: 'ProfileManager' object has no attribute 'create_superuser'

But my issue is should BaseUserManager already have this method? I cannot find a why to inherit the create_superuser method.

My manager is:

class ProfileManager(BaseUserManager):
      pass

And my model is:

class Profile(AbstractUser):
      
      objects = ProfileManager()

Thanks for all the help in advance!

2 Answers 2

1

BaseUserManager class does not have create_superuser nor create_user, these methods are implemented in UserManager

Which is also documented in customizing authentication documentation

If your user model defines username, email, is_staff, is_active, is_superuser, last_login, and date_joined fields the same as Django’s default user, you can install Django’s UserManager; however, if your user model defines different fields, you’ll need to define a custom manager that extends BaseUserManager providing two additional methods:

  • create_user

  • create_superuser

So you don't need to set objects attribute nor override anything as AbstractUser sets objects attribute to

 objects = UserManager()
Sign up to request clarification or add additional context in comments.

Comments

1

No, BaseUserManager doesn't have that method, but UserManager does

from django.contrib.auth.models import UserManager


class ProfileManager(UserManager):
    pass

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.