123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- from django.db import models
- from django.utils.translation import gettext_lazy as _
- from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
- from django.utils import timezone
- from .managers import UserManager
- class UserInstitution(models.Model):
- name = models.CharField(max_length=255)
- class Meta:
- verbose_name = _("User institution")
- verbose_name_plural = _("User institutions")
- class User(AbstractBaseUser, PermissionsMixin):
- first_name = models.CharField(_("first name"), max_length=150, blank=True)
- last_name = models.CharField(_("last name"), max_length=150, blank=True)
- email = models.EmailField(_("email address"), unique=True)
- is_staff = models.BooleanField(
- _("staff status"),
- default=False,
- help_text=_("Designates whether the user can log into this admin site."),
- )
- is_active = models.BooleanField(
- _("active"),
- default=True,
- help_text=_(
- "Designates whether this user should be treated as active. " "Unselect this instead of deleting accounts."
- ),
- )
- date_joined = models.DateTimeField(_("date joined"), default=timezone.now)
- institution = models.ForeignKey(
- UserInstitution, on_delete=models.CASCADE, related_name="users", null=True, blank=True
- )
- USERNAME_FIELD = "email"
- objects = UserManager() # Here
- class Meta:
- verbose_name = _("User")
- verbose_name_plural = _("Users")
|