1234567891011121314151617181920212223242526272829303132333435 |
- from django.db import models
- from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
- from django.utils.translation import gettext_lazy as _
- from phonenumber_field.modelfields import PhoneNumberField
- from .managers import UserManager
- class User(AbstractBaseUser, PermissionsMixin):
- firstname = models.CharField(max_length=30, blank=False)
- lastname = models.CharField(max_length=30, blank=False)
- # email, phone number parameters:
- # blank - the field is allowed to be blank (used for validation, null - for database)
- # null - store empty values as NULL (if char has blank and unique, null is required)
- # unique - unique
- email = models.EmailField(
- _('email address'),
- unique = True,
- blank=True,
- null=True,
- default=None)
- phone_number = PhoneNumberField(
- unique=True,
- blank=True,
- null=True,
- default=None)
- is_staff = models.BooleanField(default=False)
- is_active = models.BooleanField(default=True)
- USERNAME_FIELD = 'email'
- EMAIL_FIELD = 'email'
- REQUIRED_FIELDS = ['firstname', 'lastname', 'phone_number']
- objects = UserManager()
- def __str__(self):
- return self.email
|