Created
March 29, 2025 12:42
-
-
Save luxu/ada38246a096b96992208f3e89b8f7c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Institution(Base): | |
name = models.CharField( | |
"Nome da Instituição", | |
max_length=100 | |
) | |
city = models.ForeignKey( | |
"City", | |
verbose_name="Cidade", | |
on_delete=models.CASCADE, | |
related_name="institution_city" | |
) | |
tipo = models.CharField( | |
"Tipo de Instituição", | |
max_length=1, | |
choices=constants.INSTITUTION_TYPES, | |
default=constants.COURSE | |
) | |
email = models.EmailField( | |
"Contato/Email", | |
unique=True, | |
help_text="ex: [email protected]" | |
) | |
telephone = models.CharField( | |
"Whatszapp", | |
max_length=16, | |
help_text="ex: (99) 99999-9999" | |
) | |
date_visit = models.DateField( | |
"Data da Visita" | |
) | |
period = models.CharField( | |
"Período", | |
max_length=1, | |
choices=constants.PERIODS, | |
default=constants.MORNING | |
) | |
quantity_persons = models.IntegerField( | |
"Quantidade de Pessoas", | |
) | |
status_visit = models.CharField( | |
'Status da Visita', | |
max_length=1, | |
choices=constants.STATUS_VISIT, | |
default=constants.PENDING | |
) | |
def __str__(self): | |
return self.name | |
class Meta: | |
verbose_name = "Instituição" | |
verbose_name_plural = "Instituições" | |
constraints = [ | |
models.CheckConstraint( | |
check=models.Q(quantity_persons__gte=1) & models.Q(quantity_persons__lte=20), | |
name="quantity_persons_range" | |
) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testes
def test_quantity_persons_gte_twenty(city):
with pytest.raises(ValidationError):
institution = Institution(
name="Test Institution",
city=city,
tipo=constants.COURSE,
email="[email protected]",
telephone="(99) 99999-9999",
period=constants.MORNING,
quantity_persons=21,
status_visit=constants.PENDING
)
institution.full_clean()