Last active
October 4, 2019 02:50
-
-
Save walison17/2226bbdb7c47112dddc4944c51fa4a02 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 OrdemServico(models.Model): | |
funcionario = models.ForeignKey(Funcionario, verbose_name=u' Nome do Funcionario', on_delete=models.PROTECT) | |
cliente = models.ForeignKey(Cliente, verbose_name=u' Nome do Cliente', on_delete=models.PROTECT) | |
servicos = models.ManyToManyField(Servico, verbose_name=u'Servico ', on_delete=Models.PROTECT) | |
data_entrada = models.DateTimeField(verbose_name=u' Data de Entrada ', default=datetime.now, blank=True) | |
data_saida = models.DateTimeField(verbose_name=u'Data de Saida', blank=False, null=False) | |
valor_total = models.DecimalField(max_digits=7, decimal_places=2, blank=True) | |
def save(self, *args, **kwargs): | |
total = self.servicos.all().aggregate(total=models.Sum('preco'))['total'] | |
self.valor_total = total | |
return super().save(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment