自定义django-cms用户模型错误:值不指向字段,如何解决?

时间:2019-06-24 11:59:00

标签: django django-models django-cms

我正在尝试自定义Django用户模型,但在进行迁移时遇到此错误

<class 'cms.admin.useradmin.PageUserAdmin'>: (admin.E033) The value of 'ordering[0]' refers to 'username', which is not an attribute of 'cms.PageUser'.
<class 'cms.admin.useradmin.PageUserAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'username', which is not a callable, an attribute of 'PageUserAdmin', or an attribute or method on 'cms.PageUser'.
<class 'cms.admin.useradmin.PageUserAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'first_name', which is not a callable, an attribute of 'PageUserAdmin', or an attribute or method on 'cms.PageUser'.
<class 'cms.admin.useradmin.PageUserAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'last_name', which is not a callable, an attribute of 'PageUserAdmin', or an attribute or method on 'cms.PageUser'.
<class 'cms.admin.useradmin.PageUserAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'is_staff', which does not refer to a Field.
<class 'cms.admin.useradmin.PageUserAdmin'>: (admin.E116) The value of 'list_filter[2]' refers to 'is_active', which does not refer to a Field.

我的usermanager类:

class UserManager(BaseUserManager):
    def create_user(self,email,number,password=None,is_active=True,is_staff=False,is_admin=False):
        if not email:
            raise ValueError("error")
        if not password:
            raise ValueError ("error")
        if not number:
            raise ValueError("error")
        user_obg = self.model(
            email = self.normalize_email(email)
        )
        user_obg.set_password(password)
        user_obg.staff = is_staff
        user_obg.admin = is_admin
        user_obg.active = is_active
        user_obg.save(using=self._db)
        return user_obg
    def create_staffuser(self,email,password=None):
        user= self.create_user(
            email,
            password=password,
            is_staff=True
        )
        return user
    def create_admin(self,email,password=None):
        user= self.create_user(
            email,
            password=password,
            is_staff=True,
            is_admin=True
        )

我的用户模型:

class Cuser(AbstractBaseUser,PermissionsMixin):
    email = models.EmailField(unique=True,max_length=255)
    number = models.IntegerField(max_length=12,unique=True)
    user_name = models.CharField(max_length=100)
    active = models.BooleanField(default=True)
    staff = models.BooleanField(default=False)
    admin = models.BooleanField(default=False)
    timestamp = models.DateTimeField(auto_now_add=True)

    USERNAME_FIELD = 'number'
    REQUIRED_FIELDS = []

    def __str__(self):
        return self.name

    def get_full_name(self):
        return self.name

    def get_short_name(self):
        return self.name

    @property
    def is_staff(self):
        return self.staff

    @property
    def is_admin(self):
        return self.admin

    @property
    def is_active(self):
        return self.is_active

有什么建议吗?

0 个答案:

没有答案