class UserManager BaseUserManager def create_user self email password

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class UserManager(BaseUserManager):
def create_user(self, email, password=None):
if not email:
raise ValueError("User must have an email address")
user = self.model(email=UserManager.normalize_email(email))
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password):
user = self.create_user(email, password)
user.save(using=self._db)
return user
class User(AbstractBaseUser):
email = models.EmailField(max_length=255, unique=True, db_index=True)
first_name = models.CharField(max_length=255, blank=True)
last_name = models.CharField(max_length=255, blank=True)
USERNAME_FIELD = 'email'
is_admin = models.BooleanField(default=False)
objects = UserManager()
def get_full_name(self):
return "{0} {1}".format(self.first_name, self.last_name)
def get_short_name(self):
return self.__str__()
def __str__(self):
return self.email