Нет модуля с именем base_user - Django

В одном из моих файлов моделей в моем проекте Django я пытаюсь импортировать AbstractBaseUser и BaseUserManager из django.contrib.auth.base_user. Я проверил пакеты своего сайта, и в каталоге аутентификации Django определенно есть файл python base_user, но я получаю эту ошибку при попытке выполнить миграцию.

ImportError: No module named base_user

Если бы я использовал неправильную версию Django, она не появилась бы в моем каталоге пакетов Django правильно? Также в Pycharm, моей IDE, он не подчеркивает его красным с какими-либо ошибками.

models.py

from django.conf import settings
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from django.contrib.auth.hashers import get_hasher
from django.contrib.auth.models import PermissionsMixin
from django.db import models
from django.utils import timezone
from django.utils.text import slugify


class AccountUserManager(BaseUserManager):
    # username is not used here, but is needed for facebook login to work correctly
    def create_user(self, email, password=None, username=None, is_active=True):
        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(
                email=self.normalize_email(email),
        )

        user.set_password(password)
        user.last_login = timezone.now()
        user.language_code = settings.LANGUAGE_CODE
        user.is_active = is_active
        user.save(using=self._db)

        return user

    def create_superuser(self, email, password):
        user = self.create_user(email,
                                password=password,
                                )

        user.is_staff = True
        user.is_superuser = True
        user.save(using=self._db)
        return user


class Account(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True, max_length=255, verbose_name='Email',
                              help_text='Used for login and password recovery. Is also an account\'s display name if no Name is specified.')
    first_name = models.CharField(max_length=100, blank=True, null=True, verbose_name='First Name',
                                  help_text='User\'s first name.')
    last_name = models.CharField(max_length=100, blank=True, null=True, verbose_name='Last Name',
                                 help_text='User\'s last name.')
    date_joined = models.DateTimeField(auto_now_add=True, verbose_name='Date Joined')
    is_active = models.BooleanField(default=True, null=False, db_index=True, verbose_name='Is Active',
                                    help_text='Uncheck to prevent user from being allowed to login.')
    is_staff = models.BooleanField(default=False, null=False, verbose_name='Is Staff',
                                   help_text='Grants administrator privileges.')
    activation_key = models.CharField(max_length=40, blank=True, null=True)
    key_expires = models.DateTimeField(blank=True, null=True)

    objects = AccountUserManager()
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    def get_full_name(self):
        full_name = ''
        if self.first_name is not None:
            full_name += self.first_name
        if self.last_name is not None:
            full_name += ' ' + self.last_name
        return full_name

    # @property
    def _full_name(self):
        return self.get_full_name()

    _full_name.short_description = 'Name'
    full_name = property(_full_name)

    def get_display_name(self):
        if self.full_name.strip():
            return self.full_name.rstrip()
        return self.email.rstrip()

    @property
    def slug(self):
        if self.full_name:
            return slugify(self.full_name)
        email_parts = self.email.split('@')
        return slugify(email_parts[0])

    def __unicode__(self):
        return unicode(self.email)

    class Meta:
        verbose_name = 'User Account'
        verbose_name_plural = 'User Accounts'

0 ответов

Другие вопросы по тегам