pacho_the_python

user_model

Nov 17th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. from django.contrib.auth.models import AbstractUser
  2. from django.db import models
  3. from django.core.validators import MinLengthValidator, MinValueValidator
  4.  
  5.  
  6. class UserProfile(AbstractUser):
  7. USER_NAME_MAX_LEN = 35
  8. USER_NAME_MIN_LEN = 5
  9. PASSWORD_MAX_LEN = 25
  10. PASSWORD_MIN_LEN = 8
  11. AGE_MIN_VALUE = 18
  12. FIRST_NAME_MAX_LEN = 30
  13. FIRST_NAME_MIN_LEN = 3
  14. LAST_NAME_MAX_LEN = 30
  15. LAST_NAME_MIN_LEN = 3
  16. PHONE_MIN_LEN = 10
  17. PHONE_MAX_LEN = 30
  18.  
  19. username = models.CharField(
  20. verbose_name='Username',
  21. max_length=USER_NAME_MAX_LEN,
  22. null=False,
  23. blank=False,
  24. validators=[MinLengthValidator(USER_NAME_MIN_LEN)],
  25. unique=True
  26. )
  27.  
  28. account_email = models.EmailField(
  29. verbose_name='Email',
  30. null=False,
  31. blank=False,
  32. unique=True
  33. )
  34.  
  35. first_name = models.CharField(
  36. verbose_name='First Name',
  37. max_length=FIRST_NAME_MAX_LEN,
  38. null=True,
  39. blank=True,
  40. validators=[MinLengthValidator(FIRST_NAME_MIN_LEN)]
  41. )
  42.  
  43. last_name = models.CharField(
  44. verbose_name='Last Name',
  45. max_length=LAST_NAME_MAX_LEN,
  46. null=True,
  47. blank=True,
  48. validators=[MinLengthValidator(LAST_NAME_MIN_LEN)]
  49. )
  50.  
  51. age = models.IntegerField(
  52. verbose_name="Age",
  53. null=True,
  54. blank=True,
  55. validators=[MinValueValidator(AGE_MIN_VALUE)]
  56. )
  57.  
  58. image_url = models.URLField(
  59. verbose_name='Image URL',
  60. null=True,
  61. blank=True
  62. )
  63.  
  64. phone_number = models.CharField(
  65. verbose_name='Phone Number',
  66. max_length=PASSWORD_MAX_LEN,
  67. null=True,
  68. blank=True,
  69. validators=[MinLengthValidator(PHONE_MIN_LEN)]
  70. )
  71.  
  72. user_address = models.TextField(
  73. verbose_name='Address',
  74. null=True,
  75. blank=True
  76. )
  77.  
  78. @property
  79. def get_name(self):
  80. first = ''
  81. last = ''
  82. if self.first_name:
  83. first = self.first_name
  84. if self.last_name:
  85. last = self.last_name
  86. return f"{first} {last}"
  87.  
Add Comment
Please, Sign In to add comment