models.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.db import models
  2. from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
  3. from django.utils.translation import gettext_lazy as _
  4. from phonenumber_field.modelfields import PhoneNumberField
  5. from .managers import UserManager
  6. class User(AbstractBaseUser, PermissionsMixin):
  7. firstname = models.CharField(max_length=30, blank=False)
  8. lastname = models.CharField(max_length=30, blank=False)
  9. # email, phone number parameters:
  10. # blank - the field is allowed to be blank (used for validation, null - for database)
  11. # null - store empty values as NULL (if char has blank and unique, null is required)
  12. # unique - unique
  13. email = models.EmailField(
  14. _('email address'),
  15. unique = True,
  16. blank=True,
  17. null=True,
  18. default=None)
  19. phone_number = PhoneNumberField(
  20. unique=True,
  21. blank=True,
  22. null=True,
  23. default=None)
  24. is_staff = models.BooleanField(default=False)
  25. is_active = models.BooleanField(default=True)
  26. USERNAME_FIELD = 'email'
  27. EMAIL_FIELD = 'email'
  28. REQUIRED_FIELDS = ['firstname', 'lastname', 'phone_number']
  29. objects = UserManager()
  30. def __str__(self):
  31. return self.email