class Organization(models.Model): CREDIT = 1 PARTNER = 2 TYP_CHOICES = ( (None, 'Неизвестно'), (CREDIT, 'Кредитная'), (PARTNER, 'Партнёрская'), ) CREDITS_API = '/credits/' PARTNERS_API = '/partners/' API_URL_CHOICES = ( (CREDITS_API, 'Кредитное API'), (PARTNERS_API, 'Партнерское API'), ) id = models.UUIDField(primary_key=True, default=RandomUUID(), editable=False) name = models.CharField(max_length=200) user = models.OneToOneField(User, models.CASCADE, verbose_name='Пользователь', related_name='organization') api_access = models.CharField('Доступ к API', max_length=20, null=True, blank=True, choices=API_URL_CHOICES) typ = models.SmallIntegerField('Тип организации', choices=TYP_CHOICES, db_index=True, editable=False) def __str__(self): return self.name
def test_random_uuid(self): m1 = UUIDTestModel.objects.create() m2 = UUIDTestModel.objects.create() UUIDTestModel.objects.update(uuid=RandomUUID()) m1.refresh_from_db() m2.refresh_from_db() self.assertIsInstance(m1.uuid, uuid.UUID) self.assertNotEqual(m1.uuid, m2.uuid)
class Claim(models.Model): NEW = 'N' SENT = 'S' STATUS_CHOICES = ( (NEW, 'Новая'), (SENT, 'Отправленная'), ) id = models.UUIDField(primary_key=True, default=RandomUUID(), editable=False) created = models.DateTimeField('Создано', auto_now_add=True) partner = models.ForeignKey(PartnerOrganization, models.CASCADE, verbose_name='Партнёрска организация', null=True) sent = models.DateTimeField('Отправлено', null=True, blank=True) questionnaire = models.ForeignKey(Questionnaire, models.CASCADE, verbose_name='Анкета клиента') offer = models.ForeignKey(Offer, models.CASCADE, verbose_name='Предложение') status = models.CharField('Статус', max_length=1, choices=STATUS_CHOICES, default=NEW) class Meta: verbose_name = 'Заявка' verbose_name_plural = 'Заявки' def __str__(self): return 'Заявка на "{}..."'.format(self.offer.name[:40]) @property def questionnaire_display(self): return str(self.questionnaire) @property def offer_dispaly(self): return str(self.offer) @property def status_display(self): return self.get_status_display()
class Questionnaire(models.Model): id = models.UUIDField(primary_key=True, default=RandomUUID(), editable=False) created = models.DateTimeField('Создано', auto_now_add=True) updated = models.DateTimeField('Изменено', auto_now=True) surname = models.CharField('Фамилия', max_length=100) first_name = models.CharField('Имя', max_length=100) patronymic = models.CharField('Отчество', max_length=100) birth_date = models.DateField('Дата рождения') phone_num = models.CharField('Номер телефона', max_length=30) pass_ser = models.CharField('Серия паспорта', max_length=5) pass_num = models.CharField('Номер паспорта', max_length=6) score = models.IntegerField('Скоринговый балл', blank=True, null=True) organization = models.ForeignKey(Organization, models.CASCADE, verbose_name='Партнёр', null=True) class Meta: verbose_name = 'Анкета' verbose_name_plural = 'Анкеты' @property def full_name(self): return ' '.join((self.surname, self.first_name, self.patronymic)) @property def passport(self): return '{} {}'.format(self.pass_ser, self.pass_num) @passport.setter def passport(self, value): val = str(value).replace(' ', '') self.pass_ser = '{} {}'.format(val[0:2], val[2:4]) self.pass_num = val[4:] @passport.deleter def passport(self): self.pass_ser = None self.pass_num = None def __str__(self): return self.full_name
class Election(models.Model): """ An election in which a voter may have voted. """ id = models.UUIDField( primary_key=True, default=RandomUUID(), editable=False, help_text='Randomly generated universal unique identifier.', ) date = models.DateField() name = models.CharField(max_length=100) class Meta: unique_together = (("date", "name"), ) ordering = ['-date', 'name'] def __str__(self): return f'{self.name} ({self.date})'
class Offer(models.Model): CONSUMER = 'C' MORTGAGE = 'M' AUTO = 'A' CSMB = 'B' TYPE_CHOICES = ( (CONSUMER, 'Потребительский'), (MORTGAGE, 'Ипотечный'), (AUTO, 'Автокредит'), (CSMB, 'КМСБ'), ) id = models.UUIDField(primary_key=True, default=RandomUUID(), editable=False) created = models.DateTimeField('Создано', auto_now_add=True) updated = models.DateTimeField('Изменено', auto_now=True) rotation_start = models.DateTimeField('Начало ротации', null=True, blank=True) rotation_finish = models.DateTimeField('Окончание ротации', null=True, blank=True) name = models.CharField('Название', max_length=200) typ = models.CharField('Тип', max_length=1, choices=TYPE_CHOICES, default=CONSUMER) min_score = models.IntegerField('Минимальный балл', default=0, blank=True) max_score = models.IntegerField('Максимальный балл', null=True, blank=True) organization = models.ForeignKey(Organization, models.CASCADE, verbose_name='Кредитная организация') class Meta: verbose_name = 'Предложение' verbose_name_plural = 'Предложения' def __str__(self): return '{} ({})'.format(self.name, self.organization) @property def type(self): return self.get_typ_display()