Помогите разобраться, в чем дело?
файл employee/models.py
from django.db import models
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
DEP_CHOICES = [
('HR', 'Отдел кадров'),
('BUH', 'Бухгалтерия'),
('SALE', 'Продажи'),
('SEO', 'Руководство')
]
class EmpManager(BaseUserManager):
def create_user(self, department, fio, email, password=None, **other_fields):
if not department or not fio or not email or not password:
raise ValueError('Недостаточно данных для регистрации сотрудника')
email = self.normalize_email(email)
user = Employee(department=department, fio=fio, email=email, **other_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, department, fio, email, password=None):
return self.create_user(department, fio, email, password, is_staff=True, is_superuser=True)
class Employee(AbstractBaseUser):
tabel = models.BigAutoField('Табельный номер', primary_key=True)
department = models.CharField('Отдел', choices=DEP_CHOICES, max_length=50)
email = models.EmailField('Почта', max_length=50)
fio = models.CharField('ФИО', max_length=100)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
USERNAME_FIELD = 'tabel'
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = ['department', 'fio', 'email']
objects = EmpManager()
class EmpBackend(ModelBackend):
def authenticate(self, request, tabel=None, password=None, department=None, **kwargs):
if tabel is None or department is None or password is None:
return
user = Employee.objects.filter(tabel=tabel, department=department)
if user and user.get().check_password(password):
return user
return
def get_user(self, user_id):
user = Employee.objects.filter(tabel=user_id)
if user:
return user.get()
return
данные из файла settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'employee',
]
AUTH_USER_MODEL = 'employee.Employee'
AUTHENTICATION_BACKENDS = ['employee.models.EmpBackend']
почему выдает ошибку? Пытаюсь сделать makemigrations впервые в проекте