Coverage for users/models.py: 80%
21 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-11-03 16:57 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2022-11-03 16:57 -0600
1from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
2from django.db import models
3from django.utils import timezone
4from phonenumber_field.modelfields import PhoneNumberField
5from .managers import UserManager
8class User(AbstractBaseUser, PermissionsMixin):
9 """
10 User Model
11 """
12 first_name = models.CharField(max_length=64, null=True)
13 last_name = models.CharField(max_length=64, null=True)
14 email = models.EmailField(max_length=255, unique=True)
15 phone = PhoneNumberField(null=True, blank=True)
17 is_staff = models.BooleanField(default=False)
18 is_active = models.BooleanField(default=True)
19 date_joined = models.DateTimeField(default=timezone.now, editable=False)
21 objects = UserManager()
23 USERNAME_FIELD = 'email'
24 REQUIRED_FIELDS = []
26 @property
27 def name(self):
28 if self.first_name is not None and self.last_name is not None:
29 return f'{self.first_name} {self.last_name}'
30 else:
31 return self.email