Toni Lopes
unread,Feb 22, 2023, 7:51:31 AM2/22/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django Brasil
Olá! Estou quebrando a cabeça em algo que deve ser simples.
Calcular o valor de pagamento para cada tipo de profissional de acordo com o evento que ele trabalhou.
models.py
class TipoEvento(models.Model):
tipoevento = models.CharField("Tipo evento", max_length=40, help_text="Tipo de evento")
obs = models.TextField("Obs", blank=True, null=True)
profissional_1 = models.DecimalField("Profiss1", max_digits=8, decimal_places=2)
profissional_2 = models.DecimalField("Profiss2", max_digits=8, decimal_places=2)
profissional_3 = models.DecimalField("Profiss3", max_digits=8, decimal_places=2)
class EventoRealizado(models.Model):
descricao = models.CharField("Descrição", max_length=100)
data_hora = models.DateTimeField("Data e hora", auto_now=False, auto_now_add=False)
local = models.CharField("Local", max_length=100, help_text="Local do evento")
endereco = models.CharField("Endereço", max_length=100, help_text="Endereço completo")
qtd_profiss1 = models.PositiveIntegerField("Profiss1", blank=True, null=True)
qtd_profiss2 = models.PositiveIntegerField("Profiss2", blank=True, null=True)
qtd_profiss3 = models.PositiveIntegerField("Profiss3", blank=True, null=True)
# FK
tp_evento = models.ForeignKey(TipoEvento, verbose_name="Tipo Evento", on_delete=models.CASCADE)
class Profissonais(models.Model):
nome = models.CharField("Nome", max_length=100, blank=True, null=True)
funcao = models.CharField("Função", max_length=1, choices=TP_FUNCAO, default="0")
logradouro = models.CharField("Logradouro", max_length=100, blank=True, null=True)
cidade = models.CharField("Cidade", max_length=100, blank=True, null=True)
uf = models.CharField("UF", max_length=2, blank=True, null=True)
whatsapp = models.CharField("WhatsApp", max_length=30, blank=True, null=True)
telefone = models.CharField("Tel Fixo", max_length=30, blank=True, null=True)
cpf_cnpj = models.CharField("CPF", max_length=30, blank=True, null=True)
chave_pix = models.CharField("Chave PIX", max_length=100, null=True, blank=True)
banco = models.CharField("Banco", max_length=100, blank=True, null=True)
agencia = models.CharField("Agência", max_length=255, blank=True, null=True)
conta = models.CharField("Conta", max_length=255, blank=True, null=True)
class ExtratoPagamento(models.Model):
data = models.DateField("Data", auto_now=False, auto_now_add=False)
valor_extra = models.DecimalField("Valor Extra a pagar", max_digits=5, decimal_places=2, blank=True, null=True)
descr_extra = models.CharField("Descrição Extra", max_length=200, blank=True, null=True)
total_pg = models.DecimalField("Total Pagar", max_digits=5, decimal_places=2)
data_pg = models.DateField("Data Pg", auto_now=False, auto_now_add=False, blank=True, null=True)
pg_ok = models.CharField("Pg OK?", max_length=1, choices=SIM_NAO_CHOICES, blank=True, null=True)
# FK
valor_tabela = models.ForeignKey(TipoEvento, verbose_name="Valor Evento", on_delete=models.CASCADE)
profissional = models.ForeignKey(Profissonais, verbose_name='Profissionais', on_delete=models.PROTECT)
evento = models.ForeignKey(EventoRealizado, on_delete=models.CASCADE)
#
Admin.py
@admin.register(ExtratoPagamento)
class ExtratoAdmin(admin.ModelAdmin):
model = ExtratoPagamento
list_display = ['data', '_tipo_evento', '_funcao', 'valor_extra', --- aqui o campo: '_valor_tabela' ---- , 'total_pg', 'data_pg', 'pg_ok'] #
fieldsets = (...)
def _funcao(self, obj):
return obj.profissional.funcao
_funcao.short_description = 'Função'
def _tipo_evento(self, obj):
return obj.evento.tp_evento.tipoevento
_tipo_evento.short_description = 'Tipo Evento'
### aqui está o que preciso ### não chego a uma conclusão.. tentei várias...
def _valor_tabela(self, obj):
if self._tipo_evento == 'Aniversário' and self._funcao == 'Profiss1':
return obj.tipoevento.profissional_1
elif ...
elif ... repete-se, talvez com um FOR... para trazer o resultado correto da tabela do bd.
_valor_tabela.short_description = 'Valor Tabela'
################## TABELA DO BD
ID tipoevento obs profissional_1 profissional_2 profissional_3
1 Anversário 400 300 100
2 Quinze Anos 200 150 60
3 Casamento 400 270 100
4 Bodas 400 350 120