用django根据字段的值在css中添加样式
Add a style in css depending on the value of the field with django
我正在尝试设计我的代码行:
<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 %}
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})
尝试:
{% if inven.quantityInventory < 10 %}
<td class="color-green-primary">{{inven.quantityInventory}}</span></td>
{% else %}
<td class="color-red-primary">{{inven.quantityInventory}}</span></td>
{% endif %}
您应该与 inven.quantityInventory
而不仅仅是 inven
进行比较。将模型实例与 int 进行比较没有意义,与 int 属性进行比较
<td class="{% if inven.quantityInventory < 10 %}color-green-primary{% else %}color-red-primary{% endif %}">{{ inven.quantityInventory }}</span></td>
我正在尝试设计我的代码行:
<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 %}
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})
尝试:
{% if inven.quantityInventory < 10 %}
<td class="color-green-primary">{{inven.quantityInventory}}</span></td>
{% else %}
<td class="color-red-primary">{{inven.quantityInventory}}</span></td>
{% endif %}
您应该与 inven.quantityInventory
而不仅仅是 inven
进行比较。将模型实例与 int 进行比较没有意义,与 int 属性进行比较
<td class="{% if inven.quantityInventory < 10 %}color-green-primary{% else %}color-red-primary{% endif %}">{{ inven.quantityInventory }}</span></td>