django.core.exceptions.FieldError:为自由职业者指定的未知字段(is_admin)

时间:2016-07-15 21:24:33

标签: django

models.py

$('.dropdown').toggleClass('hide-arrow')

这就是我得到的确切错误

class MyUserManager(BaseUserManager):
    def create_user(self, name, skills, password=None):

        if not name:
            raise ValueError('Users must have a unique name ')

        user = self.model(
            name=self.name,
            skills=skills,
        )
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, name, skills, password):
        """
        Creates and saves a superuser with the given email, date of
        birth and password.
        """
        user = self.create_user(
            name,
            password=password,
            skills=skills,
        )
        user.is_admin = True
        user.save(using=self._db)
        return user


class Freelancer(AbstractBaseUser, PermissionsMixin):
    name = models.CharField(max_length=20, unique='true')
    Password = models.CharField(max_length=20)
    field_of_interest = models.CharField(max_length=200)
    skills = models.TextField()
    experience = models.TextField()

    USERNAME_FIELD = 'name'
    REQUIRED_FIELDS = ['skills']

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def get_absolute_url(self):
        return "/users/%s/" % urlquote(self.name)

    def get_short_name(self):
        return self.name

    def get_full_name(self):
        return self.name

    def __str__(self):  # __unicode__ on Python 2
        return self.name
    #
    # def has_perm(self, perm, obj=None):
    #     # "Does the user have a specific permission?"
    #     # # Simplest possible answer: Yes, always
    #     return True

    def has_module_perms(self, applabel):
        # "Does the user have permissions to view the app `app_label`?"
        # Simplest possible answer: Yes, always
        return True

    # @property
    # def is_staff(self):
    #     # "Is the user a member of staff?"
    #     # "Simplest possible answer: All admins are staf"
    #     return self.is_admin

1 个答案:

答案 0 :(得分:0)

我得到了解决方案,我只需要在类Freelancer中添加这两行就行了 - is_active = models.BooleanField(default = True) is_admin = models.BooleanField(default = False)