models.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 UserInstitution(models.Model):
  7. name = models.CharField(max_length=255)
  8. class Meta:
  9. verbose_name = _("User institution")
  10. verbose_name_plural = _("User institutions")
  11. class User(AbstractBaseUser, PermissionsMixin):
  12. first_name = models.CharField(_("first name"), max_length=150, blank=True)
  13. last_name = models.CharField(_("last name"), max_length=150, blank=True)
  14. email = models.EmailField(_("email address"), unique=True)
  15. is_staff = models.BooleanField(
  16. _("staff status"),
  17. default=False,
  18. help_text=_("Designates whether the user can log into this admin site."),
  19. )
  20. is_active = models.BooleanField(
  21. _("active"),
  22. default=True,
  23. help_text=_(
  24. "Designates whether this user should be treated as active. " "Unselect this instead of deleting accounts."
  25. ),
  26. )
  27. date_joined = models.DateTimeField(_("date joined"), default=timezone.now)
  28. institution = models.ForeignKey(
  29. UserInstitution, on_delete=models.CASCADE, related_name="users", null=True, blank=True
  30. )
  31. USERNAME_FIELD = "email"
  32. objects = UserManager() # Here
  33. class Meta:
  34. verbose_name = _("User")
  35. verbose_name_plural = _("Users")