How to use conditionals with mathfilters?

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)

Please post the juicio model and the code in the view that calculates the total_pagos value.

ready, I already put more information about my views and models :smiley:

Where does this value come from?

It may be helpful if you rendered the values for juicio.costo_servicio and total_pagos inside the for loop but before the if tag so that you can verify the values being used for the comparison.

Sure, Sum(‘monto_pago’) comes from Pagos models.py, In the post I just put the information about that model, I had not put it. Ok I will try what you mentioned to see the values ​​it sends

ok I try this but anyway it doesn’t work D:

 {% for juicio in juicios %}
             {{ juicio.costo_servicio|sub:total_pagos }}
             {{ total_pagos }}
             {% if juicio.costo_servicio|sub:total_pagos == 0.00 %}
                     <td class="text-right"><span class="saldo-pagado" ><strong>PAGADO</strong> 
                     </span</td>
              {% endif %}
   {% endfor %}

Please be more specific.

What do you mean by “doesn’t work”?

you’re right, I mean It doesn’t show the td and the span tag which should say “Pagado”

But what values are you seeing displayed for those variables? We’re trying to figure out why the if tag is always false.

okok this This {{ juicio.costo_servicio|sub:total_pagos }} shows its value, this one does not {{ total_pagos }} when it is inside the for, but if I leave this {{ total_pagos }} outside the for, it shows its value

Please render just {{ juicio.costo_servicio }}, and show the values being rendered.

Please clarify what you mean by: