""" This module provides class definition to manage User objects. Available classes: - UserManager: interface through which database query operations are provided to model. """ from django.contrib.auth.models import BaseUserManager class UserManager(BaseUserManager): """ Interface through which database query operations are provided to User model. """ def _create_user(self, email, password, is_staff, is_superuser, **extra_fields): """ Creates and saves an active User with the given email and password. """ if not email: raise ValueError('Users must have an email address') email = self.normalize_email(email) name = '' if is_superuser: name='Super User' user = self.model(email=email, age=0, name=name, is_staff=is_staff, is_active=True, is_superuser=is_superuser, **extra_fields) user.set_password(password) user.save(using=self._db) return user def create_user(self, email, password=None, **extra_fields): return self._create_user(email, password, False, False, **extra_fields) def create_superuser(self, email, password, **extra_fields): return self._create_user(email, password, True, True, **extra_fields)