Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active November 5, 2019 02:41
Show Gist options
  • Save walison17/8114a1102cd4526f24689a107dd3c3e5 to your computer and use it in GitHub Desktop.
Save walison17/8114a1102cd4526f24689a107dd3c3e5 to your computer and use it in GitHub Desktop.
def save_model(self, request, obj, form, change):
obj = super().save_model(request, obj, form, change)
form.save_m2m()
total = obj.item_pedido.aggregate(total=Sum('valor_item_pedido_qtd'))['total']
obj.valor_total = total
obj.save(update_fields=['total'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment