Ошибка Django : "auth.User.groups" и "auth.User.user_permissions"
У меня есть ошибка в моем приложении Django Я создал CustomUserModel
:
class CustomUserManager(UserManager):
def create_student(self, username, email, password, **extra_fields):
extra_fields.setdefault('is_student', True)
return self._create_user(username, email, password, **extra_fields)
def create_teacher(self, username, email, password, **extra_fields):
extra_fields.setdefault('is_teacher', True)
return self._create_user(username, email, password, **extra_fields)
def _create_user(self, username, email, password, **extra_fields):
if not email:
raise ValueError('The Email field must be set')
email = self.normalize_email(email)
user = self.model(username=username, email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, username=None, email=None, password=None, **extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self.create_student(username, email, password, **extra_fields)
def create_superuser(self, username=None, email=None, password=None, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self.create_teacher(username, email, password, **extra_fields)
У меня есть два типа пользователей Teacher
и Student
:
Student
class Student(AbstractBaseUser, PermissionsMixin):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
username = models.CharField(max_length=10)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField(max_length=254, blank=True, default='')
age = models.IntegerField()
student_class = models.ForeignKey(StudentClass, on_delete=models.CASCADE, related_name='students')
is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_student = models.BooleanField(default=True)
is_teacher = models.BooleanField(default=False)
# Other fields ..
objects = CustomUserManager()
Teacher
class Teacher(AbstractBaseUser, PermissionsMixin):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
username = models.CharField(max_length=10)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField(max_length=254, blank=True, default='')
is_active = models.BooleanField(default=True)
is_superuser = models.BooleanField(default=True)
is_staff = models.BooleanField(default=True)
is_student = models.BooleanField(default=False)
is_teacher = models.BooleanField(default=True)
# Other fields ...
objects = CustomUserManager()
и когда я делаю python manage.py makemigrations
, я получаю следующие ошибки:
Я пытался добавить AUTH_USER_MODEL
к settings.py
, но это не сработало, и я думаю, потому что у меня два разных пользователя.