I want to extend my django usercreation in django mongodb . Have created a class which extends User model , also have added AUTH_USER_MODEL = "users.XYZUser" in my settings.py ....here is my models.py
class XYZUserManager(BaseUserManager):
def create_user(self, email,role_id, password=None, **extra_fields):
"""
Creates and saves a User with the given username, email and password.
"""
now = timezone.now()
if not email:
raise ValueError('The given username must be set')
email = XYZUserManager.normalize_email(email)
user = self.model(email=email,
is_staff=False, is_active=True, is_superuser=False,
last_login=now, date_joined=now,role_id=role_id,emailId=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, role_id,password, **extra_fields):
u = self.create_user(email,role_id, password, **extra_fields)
u.is_staff = True
u.is_active = True
u.is_superuser = True
u.save(using=self._db)
return u
class XYZUser(User):
#id=models.AutoField(primary_key=True)
role_id=models.IntegerField(choices=ROLES,default=2)
emailId=models.EmailField(unique=True)
#is_active =models.BooleanField()
#is_staff=models.BooleanField()
#date_joined = models.DateTimeField()
#is_superuser = models.BooleanField()
#last_login = models.DateTimeField()
REQUIRED_FIELDS = ['role_id', 'emailId']
USERNAME_FIELD = 'emailId'
objects = UserManager()
when i run /manage.py syncdb i am getting following error
CommandError: One or more models did not validate: permission_backend_nonrel.userpermissionlist: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
any idea what i am missing. I agenda is to use email as login field instead of username along with some extra fields.
I am using norel permission for authentication
AUTHENTICATION_BACKENDS = (
'permission_backend_nonrel.backends.NonrelPermissionBackend',
)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djangotoolbox',
'users',
'permission_backend_nonrel',
)