Подскажите, как правильно добавить условие:
{% if item.reg_price < 50 %}
{% price = item.reg_price + (item.reg_price/100*11,73)+ (item.reg_price/100*24,6) %}
<td>{{ price }}</td>
{% elif 50 <= item.reg_price <= 500 %}
{% price = item.reg_price + (item.reg_price/100*12) + (item.reg_price/100*24,9) %}
<td>{{ price }}</td>
{% elif item.reg_price < 500 %}
{% price = item.reg_price + (item.reg_price/100*11,75) + (item.reg_price/100*24,3) %}
<td>{{ price }}</td>
{% endif %}
в templates:
{% elif target == 'reestr' %}
<table class="table table-bordered table-condensed table" onselectstart="return false">
<thead>
<tr class="info">
<th class="text-center">Наименование</th>
<th class="text-center">Производитель</th>
<th class="text-center">Цена</th>
</tr>
</thead>
<tbody>
{% for item in item_list %}
<tr class="active">
<td>{{ item.trade_name }}</td>
<td>{{ item.fabr_name}}</td>
<td>{{ item.reg_price }}</td> #здесь использовать условие
</tr>
{% endfor %}
</tbody>
</table>
Модель:
class TblReestr(models.Model):
id = models.IntegerField(primary_key=True) # AutoField?
ean13 = models.CharField(max_length=50, blank=True, null=True)
reg_price = models.DecimalField(max_digits=15, decimal_places=2, blank=True, null=True)
trade_name = models.CharField(max_length=1000, blank=True, null=True)
fabr_name = models.CharField(max_length=500, blank=True, null=True)
reg_data = models.DateField(blank=True, null=True)
mnn_name = models.CharField(max_length=250, blank=True, null=True)
valuta_name = models.CharField(max_length=20, blank=True, null=True)
num_prikaz = models.CharField(max_length=30, blank=True, null=True)
class Meta:
managed = False
db_table = 'tbl_reestr'
Views:
def search(request):
q = request.GET['q']
target = request.GET['target']
title = request.GET['title']
if target == 'brak':
item_list = TblBrak.objects.filter(trade_name__icontains=q)
elif target == 'reestr':
item_list = TblReestr.objects.filter(trade_name__icontains=q)
Подскажите, как правильно в templates использовать такое условие.