Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. class UserManager(BaseUserManager):
  2. use_in_migrations = True
  3.  
  4. def _create_user(self, email, password, is_staff, is_superuser, is_active, **extra_fields):
  5. if 'username' in extra_fields:
  6. del extra_fields['username']
  7.  
  8. email = self.normalize_email(email)
  9. user = self.model(email=email, is_staff=is_staff, is_superuser=is_superuser, is_active=is_active,
  10. **extra_fields)
  11. user.set_password(password)
  12. user.save(using=self._db)
  13. return user
  14.  
  15. def create_user(self, email, password=None, is_active=False, **extra_fields):
  16. return self._create_user(email, password, False, False, is_active, **extra_fields)
  17.  
  18. def create_superuser(self, email, password, **extra_fields):
  19. return self._create_user(email, password, True, True, True, **extra_fields)
  20.  
  21.  
  22. class User(AbstractBaseUser, PermissionsMixin):
  23. first_name = models.CharField('Имя', max_length=255, null=True, blank=True)
  24. last_name = models.CharField('Фамилия', max_length=255, null=True, blank=True)
  25. patronymic = models.CharField('Отчество', max_length=255, null=True, blank=True)
  26. email = models.EmailField('Почтовый Адрес', unique=True, error_messages={'unique': 'Этот адрес уже используется'})
  27.  
  28.  
  29. phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$')
  30. phone = models.CharField('Телефон', validators=[phone_regex], max_length=32)
  31.  
  32. location = models.CharField('Место жительства', max_length=255, null=True, blank=True)
  33. balance = models.FloatField('Баланс', default=0.0)
  34.  
  35. sex = models.CharField('Пол', choices=Choices.SEX, default=Choices.MALE, max_length=255)
  36.  
  37. date_of_birth = models.DateTimeField('День рождения', null=True, blank=True)
  38. date_joined = models.DateTimeField('Дата регистрации', default=timezone.now)
  39. height = models.IntegerField('Рост', null=True, blank=True)
  40. weight = models.IntegerField('Вес', null=True, blank=True)
  41.  
  42. appearance = models.CharField('Внешность',
  43. choices=Choices.APPEARANCE_CHOICES,
  44. default=Choices.SLAV,
  45. max_length=255)
  46.  
  47. body_type = models.CharField('Телосложение',
  48. choices=Choices.BODY_TYPE_CHOICES,
  49. default=Choices.SPORT,
  50. max_length=255)
  51.  
  52. hair_color = models.CharField('Цвет волос',
  53. choices=Choices.HAIR_COLOR_CHOICES,
  54. default=Choices.BROWN,
  55. max_length=255)
  56.  
  57. zodiac_type = models.CharField('Знак зодиака', max_length=255, null=True, blank=True,
  58. choices=Choices.ZODIAC_TYPE,
  59. default=Choices.STRELEC)
  60.  
  61. work_activity = models.CharField('Род занятий',max_length=1024, null=True, blank=True)
  62. hobbies = models.CharField('Увлечения', max_length=1024, null=True, blank=True)
  63.  
  64. polit_views = models.CharField('Политические взгляды',
  65. choices=Choices.POLIT_VIEWS,
  66. default=Choices.LIBERAL,
  67. max_length=255)
  68. foot_views = models.CharField('Отношение к еде',
  69. choices=Choices.FOOT_VIEWS_CHOICES,
  70. default=Choices.NORMAL,
  71. max_length=255)
  72.  
  73. childs = models.BooleanField('Дети', default=False)
  74.  
  75. temperament = models.CharField('Темперамент',
  76. choices=Choices.TEMPERAMENT_CHOICES,
  77. default=Choices.SANGUIS,
  78. max_length=255)
  79.  
  80. person_type = models.CharField('Тип личности',
  81. choices=Choices.PERSON_TYPE_CHOICES,
  82. default=Choices.EXTROVERT,
  83. max_length=255)
  84.  
  85. religion_views = models.CharField('Религиозные взгляды',
  86. choices=Choices.RELIGION_VIEWS,
  87. default=Choices.AGNOSTIC,
  88. max_length=255)
  89.  
  90. alcogol_views = models.CharField('Отношение к алкоголю',
  91. choices=Choices.ALCO_VIEWS,
  92. default=Choices.NEUTRAL,
  93. max_length=255)
  94.  
  95. smoke_views = models.CharField('Отношение к курению',
  96. choices=Choices.SMOKE_VIEWS,
  97. default=Choices.NEUTRAL,
  98. max_length=255)
  99.  
  100. is_staff = models.BooleanField(_('staff status'),
  101. default=False,
  102. help_text=_('Designates whether the user can log into this admin site.'))
  103.  
  104. is_active = models.BooleanField(_('active'),
  105. default=True,
  106. help_text=_('Designates whether this user should be treated as '
  107. 'active. Unselect this instead of deleting accounts.'))
  108.  
  109. image = models.ImageField('Аватар', upload_to='img/main')
  110.  
  111. # enum
  112. objects = UserManager()
  113. USERNAME_FIELD = 'email'
  114. REQUIRED_FIELDS = ['first_name', 'last_name']
  115.  
  116. def get_full_name(self):
  117. return self.first_name + self.last_name + self.middle_name
  118.  
  119. def get_short_name(self):
  120. return self.first_name
  121.  
  122. def _get_zodiac_type(self):
  123. pass
  124.  
  125. class Meta:
  126. verbose_name = 'Пользователь'
  127. verbose_name_plural = 'Пользователи'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement