Hello, I have a question, I am doing a project in Django and there is a part of the application called Payments, there I show the following: payments made, total payment and pending payment,
To show the information of these payments I am using mathfilters because addition and subtraction are used.
For the template it is showing the information properly, only the problem comes when I want to use conditionals since once pending payment is equal to 0.00 it means that the client already pays everything and must show a text that says “PAGADO” (paid), when pending payment it has another figure other than 0.00 must show a label that says “PENDIENTE” (pending).
This is the code that I am using and it works, since it shows me the result of the amount of the service cost minus the total payments, whatever it shows is the pending payment, it can show several numbers or 0.00
{% for juicio in juicios %}
{{ juicio.costo_servicio|sub:total_pagos }}
{% endfor %}
But if I show this, it does not enter the if and therefore does not do the subtraction or show the text PAGADO(paid)
{% for juicio in juicios %}
{% if juicio.costo_servicio|sub:total_pagos == 0.00 %}
{{ juicio.costo_servicio|sub:total_pagos }}
<td class="text-right"><span class="saldo-pagado" ><strong>PAGADO</strong></span></td>
{% endif %}
{% endfor %}
juicios models.py
class Juicios(models.Model):
cliente = models.ForeignKey(Cliente, on_delete=models.CASCADE)
no_expediente_cv = models.CharField(max_length=100)
costo_servicio=models.DecimalField(max_digits=10, decimal_places=2)
pagos models.py
class Pagos(models.Model):
cliente = models.ForeignKey(Cliente, on_delete=models.CASCADE)
monto_pago=models.IntegerField()
pagos view.py
def PagosDetalle(request, cliente_id):
context = {}
cliente = Cliente.objects.get(id=cliente_id)
pagos = Pagos.objects.filter(cliente=cliente_id)
juicios = Juicios.objects.filter(cliente=cliente_id)
total_pagos = Pagos.objects.filter(cliente=cliente).aggregate(sum_of_all_orders=Sum('monto_pago'))
pagos_filtrados=Pagos.objects.filter(cliente=cliente)
context["pagos"] = pagos
context["pagos_filtrados"] = pagos_filtrados
context["total_pagos"] = total_pagos['sum_of_all_orders']
if juicios:
context["juicios"] = juicios
return render(request, "pagos-detalle.html",context)