用django norel扩展django auth

时间:2014-05-28 17:31:41

标签: django mongodb django-nonrel

我想在django mongodb中扩展我的django usercreation。创建了一个扩展User模型的类,还在我的settings.py中添加了AUTH_USER_MODEL =“users.XYZUser”....这里是我的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()

当我运行/manage.py syncdb时出现以下错误

CommandError:一个或多个模型未验证: permission_backend_nonrel.userpermissionlist:'user'定义与模型'auth.User'的关系,该模型已被换出。更新关系以指向settings.AUTH_USER_MODEL。

任何想法我错过了什么。我的议程是使用电子邮件作为登录字段而不是用户名以及一些额外的字段。

我正在使用norel权限进行身份验证

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',

1 个答案:

答案 0 :(得分:0)

尝试从 AbstractUser AbstractBaseUser 继承类 XYZUser