Home > Back-end >  Add a style in css depending on the value of the field with django
Add a style in css depending on the value of the field with django

Time:03-12

I'm trying to style my line of code:

<td >{{inven.quantityInventory}}</span></td>

It should change color depending on the value that is presented. The bad thing is that it always shows it to me in red (in else). what am I doing wrong?

html

                             {% for inven in inventory %}
                                <tr>
                                   <td><strong>{{inven.codigoInventory}}</strong></td>
                                   <td>{{inven.descriptionInventory}}</td>
                                   <td>${{inven.unitPriceInventory}}</td>
                                   <td >{{inven.quantityInventory}}</span></td>
                                   <td>{{inven.dealer}}</td>
                                   <td>{{inven.invoiceNumber}}</td>
                                   <td>
                                      <div >{{inven.status}}</div>
                                   </td>
                                   <td><a href="{% url 'inventory:inventory_detail' inven.id%}">Detail</a></td>
                                   <td><a href="{% url 'inventory:edit_inventory' inven.id%}">Edit</a></td>
                                   <td><a href="{% url 'inventory:eliminar_inventory' inven.id%}"  >Delete</a></td>
                                </tr>
                                {% endfor %}

views.py

def list_inventory(request):

    if request.method == 'POST':
        fromdate=request.POST.get('fromdate')
        todate = request.POST.get('todate')
        searchresult = Inventory.objects.filter(fecha_registro__range=(fromdate, todate))
        return render(request,'inventory/inventory-list.html',{'inventory':searchresult})

    else:
        displaydata = Inventory.objects.all()
    return render(request, 'inventory/inventory-list.html', {'inventory': displaydata})

CodePudding user response:

You should be comparing against inven.quantityInventory not just inven. It does not make sense to compare a model instance with an int, compare against an int attribute

<td >{{ inven.quantityInventory }}</span></td>

CodePudding user response:

Try:

{% if inven.quantityInventory < 10 %}
<td >{{inven.quantityInventory}}</span></td>
{% else %}
<td >{{inven.quantityInventory}}</span></td>
{% endif %}
  • Related