AUTH_USER_MODEL improperly configured
sandeshnaroju opened this issue · comments
I am getting the following error as soon as I add 'RolePermissionsUserAdminMixin' to my custom user model which is from AbstractBaseUser. I am trying to add Roles and Permissions to django Admin. I have set
ROLEPERMISSIONS_REGISTER_ADMIN = True
Traceback (most recent call last):
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
autoreload.raise_last_exception()
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sandesh/wpos/wpos/reglog/models.py", line 9, in <module>
from rolepermissions.admin import RolePermissionsUserAdminMixin
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/rolepermissions/admin.py", line 4, in <module>
from django.contrib.auth.admin import UserAdmin
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/contrib/auth/admin.py", line 7, in <module>
from django.contrib.auth.forms import (
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 22, in <module>
UserModel = get_user_model()
File "/home/sandesh/wpos/virtualenvwpos/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 199, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'reglog.User' that has not been installed
MY USER MODEL:
from __future__ import unicode_literals
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser
)
from django.db import models
from rolepermissions.admin import RolePermissionsUserAdminMixin
class MyUserManager(BaseUserManager):
def create_user(self, email, password=None):
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password):
user = self.create_user(email,
password=password,
)
user.is_admin = True
user.is_active = True
user.save(using=self._db)
return user
class User(RolePermissionsUserAdminMixin,AbstractBaseUser):
account_id = models.CharField(max_length=50, default="")
ref_id = models.CharField(max_length=50, default="")
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
first_name = models.CharField(max_length=50, default="")
last_name = models.CharField(max_length=50, default="")
username = models.CharField(max_length=50, default="", unique=True)
phonenumber = models.CharField(max_length=50, default="", unique=True)
image = models.CharField(max_length=1500, default="")
address = models.CharField(max_length=1500, default="")
country = models.CharField(max_length=50, default="")
role = models.CharField(max_length=50, default="")
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
date_joined = models.DateTimeField(auto_now=False, auto_now_add=True)
last_login = models.DateTimeField(auto_now=True, auto_now_add=False)
is_deleted = models.BooleanField(default=False)
objects = MyUserManager()
USERNAME_FIELD = 'email'
@property
def get_full_name(self):
return self.first_name + " " + self.last_name
def get_short_name(self):
return self.first_name
def __unicode__(self): # __unicode__ on Python 2
return self.get_full_name
def has_perm(self, perm, obj=None):
return True
def has_module_perms(self, app_label):
return True
@property
def is_staff(self):
return self.is_admin
And if I remove the mixin and associated import error goes away. But I want to use this package. I am new to django. help me please.
@filipeximenes look at this issue please
Hi @sandeshnaroju, sorry for the delay. Hope you have fixed the issue by now but this probably caused by some other problem in your code not django-role-permissions directly. Please research the error message in the internet. I'll close this for now please open the issue again if you still think the problem is with this library.