Advertisement
horozov86

class Profile and class MyHolidayUser

Mar 13th, 2024
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. from django.contrib.auth.hashers import make_password
  2. from django.db import models
  3.  
  4. from django.utils.translation import gettext_lazy as _
  5. from django.contrib.auth import models as auth_models
  6.  
  7. from django.utils import timezone
  8.  
  9. from my holiday.accounts.managers import MyHolidayUserManager
  10.  
  11. class MyHolidayUser(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):
  12.     email = models.EmailField(
  13.         _("email address"),
  14.         unique=True,
  15.         error_messages={
  16.             "unique": _("A user with that email already exists."),
  17.         },
  18.     )
  19.  
  20.     date_joined = models.DateTimeField(_("date joined"), default=timezone.now)
  21.  
  22.     is_staff = models.BooleanField(
  23.         default=False,
  24.     )
  25.  
  26.     is_active = models.BooleanField(
  27.         default=True,
  28.     )
  29.  
  30.     USERNAME_FIELD = "email"
  31.  
  32.     objects = MyHolidayUserManager()
  33.    
  34.    
  35. class Profile(models.Model):
  36.     MAX_USERNAME_LENGTH = 20
  37.  
  38.  
  39.     first_name = models.CharField(
  40.         max_length=50,
  41.         null=True,
  42.         blank=True,
  43.         verbose_name='First Name',
  44.     )
  45.  
  46.     last_name = models.CharField(
  47.         max_length=50,
  48.         null=True,
  49.         blank=True,
  50.         verbose_name='Last Name',
  51.     )
  52.  
  53.     age = models.IntegerField(
  54.         null=False,
  55.         blank=False,
  56.         verbose_name='Age',
  57.     )
  58.  
  59.     profile_photo = models.URLField(
  60.         null=True,
  61.         blank=True,
  62.         verbose_name='Profile Photo',
  63.     )
  64.    
  65.     user = models.OneToOneField(
  66.         MyHolidayUser,
  67.         primary_key=True,
  68.         on_delete=models.CASCADE,
  69.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement