Reputation: 43
models.py:
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager
class UserManager(BaseUserManager):
# code
def create_user(self, uid, pass):
# code
class user(AbstractBaseUser, PermissionsMixin):
# code
objects = UserManager()
# code
class appUser(user):
# code
views.py
from projectname.app.models import appUser
def index_view(request):
# code
appUser.objects.create_user(uid_variable, pass_variable)
# code
settings.py
#code
INSTALLED_APPS = (
#code
'projectname.app',
)
AUTH_USER_MODEL = 'app.appUser'
#code
When I am trying to call a create-user method in view this exception appears. What am I doing wrong?
Upvotes: 1
Views: 8579
Reputation: 308839
Your appUser
is a subclass of user
. If user
is not an abstract base class, then appUser
will not inherit the manager, and you will need to redeclare it.
class appUser(user):
objects = UserManager()
From the docs:
Managers defined on non-abstract base classes are not inherited by child classes. If you want to reuse a manager from a non-abstract base, redeclare it explicitly on the child class. These sorts of managers are likely to be fairly specific to the class they are defined on, so inheriting them can often lead to unexpected results (particularly as far as the default manager goes). Therefore, they aren’t passed onto child classes.
Having your appUser
model subclass user
is complex, you might encounter other difficulties. I would avoid it if possible, or at least make user
abstract.
Upvotes: 4