Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserManager(BaseUserManager):
- use_in_migrations = True
- def _create_user(self, email, password, is_staff, is_superuser, is_active, **extra_fields):
- if 'username' in extra_fields:
- del extra_fields['username']
- email = self.normalize_email(email)
- user = self.model(email=email, is_staff=is_staff, is_superuser=is_superuser, is_active=is_active,
- **extra_fields)
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_user(self, email, password=None, is_active=False, **extra_fields):
- return self._create_user(email, password, False, False, is_active, **extra_fields)
- def create_superuser(self, email, password, **extra_fields):
- return self._create_user(email, password, True, True, True, **extra_fields)
- class User(AbstractBaseUser, PermissionsMixin):
- first_name = models.CharField('Имя', max_length=255, null=True, blank=True)
- last_name = models.CharField('Фамилия', max_length=255, null=True, blank=True)
- patronymic = models.CharField('Отчество', max_length=255, null=True, blank=True)
- email = models.EmailField('Почтовый Адрес', unique=True, error_messages={'unique': 'Этот адрес уже используется'})
- phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$')
- phone = models.CharField('Телефон', validators=[phone_regex], max_length=32)
- location = models.CharField('Место жительства', max_length=255, null=True, blank=True)
- balance = models.FloatField('Баланс', default=0.0)
- sex = models.CharField('Пол', choices=Choices.SEX, default=Choices.MALE, max_length=255)
- date_of_birth = models.DateTimeField('День рождения', null=True, blank=True)
- date_joined = models.DateTimeField('Дата регистрации', default=timezone.now)
- height = models.IntegerField('Рост', null=True, blank=True)
- weight = models.IntegerField('Вес', null=True, blank=True)
- appearance = models.CharField('Внешность',
- choices=Choices.APPEARANCE_CHOICES,
- default=Choices.SLAV,
- max_length=255)
- body_type = models.CharField('Телосложение',
- choices=Choices.BODY_TYPE_CHOICES,
- default=Choices.SPORT,
- max_length=255)
- hair_color = models.CharField('Цвет волос',
- choices=Choices.HAIR_COLOR_CHOICES,
- default=Choices.BROWN,
- max_length=255)
- zodiac_type = models.CharField('Знак зодиака', max_length=255, null=True, blank=True,
- choices=Choices.ZODIAC_TYPE,
- default=Choices.STRELEC)
- work_activity = models.CharField('Род занятий',max_length=1024, null=True, blank=True)
- hobbies = models.CharField('Увлечения', max_length=1024, null=True, blank=True)
- polit_views = models.CharField('Политические взгляды',
- choices=Choices.POLIT_VIEWS,
- default=Choices.LIBERAL,
- max_length=255)
- foot_views = models.CharField('Отношение к еде',
- choices=Choices.FOOT_VIEWS_CHOICES,
- default=Choices.NORMAL,
- max_length=255)
- childs = models.BooleanField('Дети', default=False)
- temperament = models.CharField('Темперамент',
- choices=Choices.TEMPERAMENT_CHOICES,
- default=Choices.SANGUIS,
- max_length=255)
- person_type = models.CharField('Тип личности',
- choices=Choices.PERSON_TYPE_CHOICES,
- default=Choices.EXTROVERT,
- max_length=255)
- religion_views = models.CharField('Религиозные взгляды',
- choices=Choices.RELIGION_VIEWS,
- default=Choices.AGNOSTIC,
- max_length=255)
- alcogol_views = models.CharField('Отношение к алкоголю',
- choices=Choices.ALCO_VIEWS,
- default=Choices.NEUTRAL,
- max_length=255)
- smoke_views = models.CharField('Отношение к курению',
- choices=Choices.SMOKE_VIEWS,
- default=Choices.NEUTRAL,
- max_length=255)
- 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.'))
- image = models.ImageField('Аватар', upload_to='img/main')
- # enum
- objects = UserManager()
- USERNAME_FIELD = 'email'
- REQUIRED_FIELDS = ['first_name', 'last_name']
- def get_full_name(self):
- return self.first_name + self.last_name + self.middle_name
- def get_short_name(self):
- return self.first_name
- def _get_zodiac_type(self):
- pass
- class Meta:
- verbose_name = 'Пользователь'
- verbose_name_plural = 'Пользователи'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement