我正在嘗試設計我的代碼行:
<td class="{% if inven < 10 %}color-green-primary{% else %}color-red-primary{% endif %}">{{inven.quantityInventory}}</span></td>
它應該根據呈現的值改變顏色。不好的是它總是以紅色(在其他情況下)顯示給我。我究竟做錯了什么?
html
{% for inven in inventory %}
<tr>
<td><strong>{{inven.codigoInventory}}</strong></td>
<td>{{inven.descriptionInventory}}</td>
<td>${{inven.unitPriceInventory}}</td>
<td class="{% if inven < 10 %}color-green-primary{% else %}color-red-primary{% endif %}">{{inven.quantityInventory}}</span></td>
<td>{{inven.dealer}}</td>
<td>{{inven.invoiceNumber}}</td>
<td>
<div class="badge bg-soft-danger font-size-12">{{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%}" class="text-danger" >Delete</a></td>
</tr>
{% endfor %}
視圖.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})
uj5u.com熱心網友回復:
您應該與inven.quantityInventory不只是比較inven。將模型實體與 int 進行比較,與 int 屬性進行比較是沒有意義的
<td class="{% if inven.quantityInventory < 10 %}color-green-primary{% else %}color-red-primary{% endif %}">{{ inven.quantityInventory }}</span></td>
uj5u.com熱心網友回復:
嘗試:
{% if inven.quantityInventory < 10 %}
<td class="color-green-primary">{{inven.quantityInventory}}</span></td>
{% else %}
<td class="color-red-primary">{{inven.quantityInventory}}</span></td>
{% endif %}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/441405.html
上一篇:如何使標題回應?
下一篇:如何減少表格行中的垂直空間?
