def _create_user(self, email, password, is_staff,
is_superuser, is_active, **extra_fields):
"""
Creates and saves a User with the given email and password.
"""
try:
now = timezone.now()
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email, is_staff=is_staff,
is_active=is_active, is_superuser=is_superuser,
date_joined=now, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
except IntegrityError:
_LOGGER.error('Cannot create new user with email %s. '
'A user with that email already exists.', email)
评论列表
文章目录