ashes999
ashes999

Reputation: 1324

Django creating super user error: AttributeError: 'ProfileManager' object has no attribute 'create_superuser'

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!

Upvotes: 0

Views: 130

Answers (2)

iklinac
iklinac

Reputation: 15748

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()

Upvotes: 1

JPG
JPG

Reputation: 88619

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

from django.contrib.auth.models import UserManager


class ProfileManager(UserManager):
    pass

Upvotes: 1

Related Questions