class User(PermissionsMixin, AbstractBaseUser): """ Model to store a user's account information. """ email = models.EmailField(unique=True, verbose_name=_('email')) email_verified = models.BooleanField(default=False, verbose_name=_('email verified')) is_staff = models.BooleanField( default=False, help_text=_('Staff users are allow to log in to the admin panel.'), verbose_name=_('is staff')) # Constants for Django EMAIL_FIELD = 'email' USERNAME_FIELD = 'email' # Custom manager objects = managers.UserManager() class Meta: verbose_name = _('user') verbose_name_plural = _('users') def get_full_name(self): """ Get the user's full name. Returns: The user's email address. """ return self.email def get_short_name(self): """ Get the user's short name. Returns: The user's email address. """ return self.email
class User(PermissionsMixin, AbstractBaseUser): """ An authenticated user on the site. """ EMAIL_FIELD = "email" REQUIRED_FIELDS = ["name"] USERNAME_FIELD = "email" created = models.DateTimeField( auto_now_add=True, help_text=_("The time when the user was created."), verbose_name=_("creation time"), ) email = models.EmailField( help_text=_("The user's email address."), unique=True, verbose_name=_("email address"), ) id = models.UUIDField( default=uuid.uuid4, help_text=_("A unique identifier for the user."), primary_key=True, verbose_name=_("ID"), ) is_active = models.BooleanField( default=True, help_text=_("Designates if the user is allowed to log in."), verbose_name=_("active status"), ) is_staff = models.BooleanField( default=False, help_text=_("Designates if the user has access to the admin site."), verbose_name=_("admin status"), ) last_login = models.DateTimeField( blank=True, help_text=_("The time of the user's last login."), null=True, verbose_name=_("last login time"), ) name = models.CharField( help_text=_("A publicly displayed name for the user."), max_length=100, verbose_name=_("name"), ) updated = models.DateTimeField( auto_now=True, help_text=_("The last time the user was updated."), verbose_name=_("update time"), ) # Custom manager objects = managers.UserManager() class Meta: ordering = ("created", ) verbose_name = _("user") verbose_name_plural = _("users") def __repr__(self): """ Returns: A string containing the information needed to reconstruct the user. """ return (f"User(email={repr(self.email)}, id={repr(self.id)}, " f"is_active={self.is_active}, is_staff={self.is_staff}, " f"is_superuser={self.is_superuser}, name={repr(self.name)})") def __str__(self): """ Returns: A user readable string describing the instance. """ return f"{self.name} ({self.email})"
class User(PermissionsMixin, AbstractBaseUser): """ A single user. """ REQUIRED_FIELDS = ['name'] USERNAME_FIELD = 'username' id = models.UUIDField( default=uuid.uuid4, help_text=_('A unique identifier for the user.'), primary_key=True, unique=True, verbose_name=_('ID'), ) is_active = models.BooleanField( default=True, help_text=_('A boolean indicating if the user account is active. ' 'Inactive accounts cannot perform actions on the site.'), verbose_name=_('is active'), ) is_staff = models.BooleanField( default=False, help_text=_('A boolean indicating if the user is allowed to access ' 'the admin site.'), verbose_name=_('is staff'), ) is_superuser = models.BooleanField( default=False, help_text=_('A boolean indicating if the user has all permissions ' 'without them being explicitly granted.'), verbose_name=_('is superuser'), ) name = models.CharField( help_text=_("The user's name."), max_length=100, verbose_name=_('full name'), ) time_created = models.DateTimeField( auto_now_add=True, help_text=_('The time the user was created.'), verbose_name=_('time created'), ) time_updated = models.DateTimeField( auto_now=True, help_text=_('The time the user was last updated.'), verbose_name=_('time updated'), ) username = models.CharField( help_text=_('The name the user logs in as.'), max_length=100, unique=True, verbose_name=_('username'), ) email = models.EmailField( help_text=_('email to contact user'), max_length=200, unique=True, verbose_name=_('email'), ) phone = PhoneNumberField( help_text=_('phone number to which menu will be texted'), null=False, blank=False, unique=True, verbose_name=_('phone number')) locations = models.ManyToManyField(Location) MEALS = [ (1, 'Continental'), (2, 'Breakfast'), (3, 'Brunch'), (4, 'Lunch'), (5, 'Late Lunch'), (6, 'Midday'), (7, 'Dinner'), (8, 'Lite Dinner'), (9, 'Late Night'), ] meals = MultiSelectField(choices=MEALS, default='') # Custom Manager objects = managers.UserManager() class Meta: ordering = ('time_created', ) verbose_name = _('user') verbose_name_plural = _('users') def __repr__(self): """ Get a string representation of the user. Returns: A string containing the information required to reconstruct the user. """ return f'User(id={self.id:r}, username={self.username:r})' def __str__(self): """ Get a string identifying the user. Returns: The user's name. """ return self.name
class User(PermissionsMixin, AbstractBaseUser): """ A single user. """ REQUIRED_FIELDS = ['name'] USERNAME_FIELD = 'username' id = models.UUIDField( default=uuid.uuid4, help_text=_('A unique identifier for the user.'), primary_key=True, unique=True, verbose_name=_('ID'), ) is_active = models.BooleanField( default=True, help_text=_('A boolean indicating if the user account is active. ' 'Inactive accounts cannot perform actions on the site.'), verbose_name=_('is active'), ) is_staff = models.BooleanField( default=False, help_text=_('A boolean indicating if the user is allowed to access ' 'the admin site.'), verbose_name=_('is staff'), ) is_superuser = models.BooleanField( default=False, help_text=_('A boolean indicating if the user has all permissions ' 'without them being explicitly granted.'), verbose_name=_('is superuser'), ) name = models.CharField( help_text=_("The user's name."), max_length=100, verbose_name=_('full name'), ) time_created = models.DateTimeField( auto_now_add=True, help_text=_('The time the user was created.'), verbose_name=_('time created'), ) time_updated = models.DateTimeField( auto_now=True, help_text=_('The time the user was last updated.'), verbose_name=_('time updated'), ) username = models.CharField( help_text=_('The name the user logs in as.'), max_length=100, unique=True, verbose_name=_('username'), ) email = models.EmailField( help_text=_('email to contact user'), max_length=200, unique=True, verbose_name=_('email'), ) # Custom Manager objects = managers.UserManager() class Meta: ordering = ('time_created', ) verbose_name = _('user') verbose_name_plural = _('users') def __repr__(self): """ Get a string representation of the user. Returns: A string containing the information required to reconstruct the user. """ return f'User(id={self.id:r}, username={self.username:r})' def __str__(self): """ Get a string identifying the user. Returns: The user's name. """ return self.name
class User(PermissionsMixin, AbstractBaseUser): """ Model representing a single user. """ USERNAME_FIELD = 'name' id = models.UUIDField( db_index=True, default=uuid.uuid4, help_text=_('A unique identifier for the user.'), primary_key=True, ) is_active = models.BooleanField( default=True, help_text=_('A boolean indicating if the user should be allowed to ' 'perform actions on the site.'), verbose_name=_('is active'), ) is_staff = models.BooleanField( default=False, help_text=_('A boolean indicating if the user is allowed to access ' 'the admin interface.'), verbose_name=_('is staff'), ) is_superuser = models.BooleanField( default=False, help_text=_('A boolean indicating if the user should have all ' 'permissions without them being explicitly granted.'), verbose_name=_('is superuser'), ) name = models.CharField( help_text=_('A name to publicly identify the user.'), max_length=127, verbose_name=_('name'), ) primary_email = models.ForeignKey( 'account.Email', blank=True, help_text=_("The user's primary email address."), null=True, on_delete=models.SET_NULL, # No backwards relationship related_name='+', verbose_name=_('primary email address'), ) time_created = models.DateTimeField( auto_now_add=True, help_text=_('The time the user was created.'), verbose_name=_('time created'), ) time_updated = models.DateTimeField( auto_now=True, help_text=_('The last time the user was edited.'), verbose_name=_('time updated'), ) # Use our custom manager objects = managers.UserManager() class Meta: ordering = ('time_created', ) verbose_name = _('user') verbose_name_plural = _('users')