models.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from django.db import models
  2. from django.utils.translation import gettext_lazy as _
  3. from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
  4. from django.utils import timezone
  5. from .managers import UserManager
  6. class User(AbstractBaseUser, PermissionsMixin):
  7. first_name = models.CharField(_("first name"), max_length=150, blank=True)
  8. last_name = models.CharField(_("last name"), max_length=150, blank=True)
  9. email = models.EmailField(_("email address"), unique=True)
  10. is_staff = models.BooleanField(
  11. _("staff status"),
  12. default=False,
  13. help_text=_("Designates whether the user can log into this admin site."),
  14. )
  15. is_active = models.BooleanField(
  16. _("active"),
  17. default=True,
  18. help_text=_(
  19. "Designates whether this user should be treated as active. " "Unselect this instead of deleting accounts."
  20. ),
  21. )
  22. date_joined = models.DateTimeField(_("date joined"), default=timezone.now)
  23. USERNAME_FIELD = "email"
  24. objects = UserManager() # Here
  25. class Meta:
  26. verbose_name = _("user")
  27. verbose_name_plural = _("users")