Last active
April 5, 2019 18:05
-
-
Save zokis/77eb1c8201013da184a664147dab4587 to your computer and use it in GitHub Desktop.
Exemplo de padrão de Choices para Django
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
# Modelo | |
class ProjetoPagamento(models.Model): | |
class TIPOS_PAGAMENTOS(object): | |
PANTIO = 1 | |
MANUTENCAO = 2 | |
PLANTIO_ADICIONAL = 3 | |
MANUTENCAO_ADICIONAL = 4 | |
CHOICES = ( | |
(PANTIO, 'Plantio'), | |
(MANUTENCAO, 'Manutenção'), | |
(PLANTIO_ADICIONAL, 'Plantio Adicional'), | |
(MANUTENCAO_ADICIONAL, 'Manutenção Adicional') | |
) | |
tipo = models.IntegerField(choices=TIPOS_PAGAMENTOS.CHOICES, null=True, blank=True) | |
valor = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True) | |
# exemplo de Uso | |
proj_pag = ProjetoPagamento.objects.get(pk=1) | |
if proj_pag.tipo == ProjetoPagamento.TIPOS_PAGAMENTOS.MANUTENCAO: | |
proj_pag.valor *= 2 | |
proj_pag.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment