2016-07-15 51 views
0

models.py指定的未知領域(S)(is_admin)django.core.exceptions.FieldError:爲自由職業者

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 "https://stackoverflow.com/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 

,這就是我得到

File "/usr/lib/python2.7/dist-packages/django/forms/models.py", line 294, in __new__ 
    raise FieldError(message) 
django.core.exceptions.FieldError: Unknown field(s) (is_admin) specified for Freelancer 
+0

哪一行是行294? – raphv

+0

因爲你沒有。或者使用'(在Django的UserManager中)is_superuser'或者在Freelancer模型中定義'is_admin = models.BooleanField(default = False)'。我想你也應該也想'is_active = models.BooleanField(default = False)' – kapilsdv

回答

0

確切的錯誤我得到了我只需要添加類自由職業者在這裏這兩條線的解決方案是line-- IS_ACTIVE = models.BooleanField(默認值= TRUE) is_admin = models.BooleanField(默認值= FALSE)

相關問題