0
0 комментариев

Создаю свой класс User по примеру из официальной документации
Вот код:

class UserManager(BaseUserManager):
 
    def create_user(self, login , password, name = None, surname = None, birthDate = None, hometown = None):
 
        user = self.model(
            login = login,
            name = name,
            surname = surname,
            birthDate = birthDate,
            hometown = hometown,
        )
 
        user.set_password(password)
 
        user.save(using=self._db)
 
        return user
 
    def create_superuser(self, login , password, name = None, surname = None, birthDate = None, hometown = None):
 
        user = self.model(
            login = login,
            name = name,
            surname = surname,
            birthDate = birthDate,
            hometown = hometown,
        )
 
        user.set_password(password)
 
        user.is_admin = True
        user.save(using=self._db)
 
        return user
 
 
class User(AbstractBaseUser):
 
    login = models.CharField(max_length = 100, unique=True)
    password = models.CharField(max_length = 100)
    name = models.CharField(max_length = 100)
    surname = models.CharField(max_length = 100)
    birthDate = models.DateTimeField()
    hometown = models.CharField(max_length = 100)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
 
    objects = UserManager()
 
    USERNAME_FIELD = 'login'
    REQUIRED_FIELDS = ['']
 
    def get_full_name(self):
        return '{} {}'.format(self.name, self.surname)
 
    def get_short_name(self):
        return '{} {}'.format(self.name, self.surname)
 
    def has_perm(self, perm, obj=None):
        return True
 
    def has_module_perms(self, app_label):
        return True
 
    @property
    def is_staff(self):
        return self.is_admin
 
    def __str__(self):
        return '{} {}'.format(self.name, self.surname)
 
    def auth(self, login, password):
        if login == self.login and password == self.password:
            return True
        return False

При попытке через shell создать объект этого класса(s = User.objects.create('nrjshka@gmail.com', 'password','Maxim', 'Korolev', datetime.now(), 'Rybinsk')) выдает следующую ошибку:

Переопределение базового класса User

P.S. Испробовал словари, кортежи и списки — ничего не помогает.


Добавить комментарий