Я пытаюсь отобразить все элементы из моего набора запросов, в данный момент он отображает только одну
Ниже приведен мой код, который возвращает только первый элемент из моего набора запросов special_list:
views.py
try:
try:
specail_list = Special.objects.get(promotion=True, sp_code=promocode, start__lte=date_instance, minimum_stay__lte=nights, object_id=room_filter.id, end__gte=date_instance, is_active=True, member_deal=False)
is_promo=True
except:
specail_list = Special.objects.filter(promotion=False, start__lte=date_instance, minimum_stay__lte=nights, object_id=room_filter.id, end__gte=date_instance, is_active=True, member_deal=False)
is_promo = False
min_stay_check_end = chek_in + datetime.timedelta(days=specail_list.minimum_stay - 1)
min_stay_check_start = check_out - datetime.timedelta(days=specail_list.minimum_stay)
if min_stay_check_end > (specail_list.end.date() + datetime.timedelta(days=1)) and (check_out + datetime.timedelta(days=1)) > specail_list.end.date():
specail_list = None
if min_stay_check_start < (specail_list.start.date() + datetime.timedelta(days=1)) and (chek_in < specail_list.start.date() + datetime.timedelta(days=1)):
specail_list = None
except:
specail_list = None
try:
for element in specail_list:
if element.discount_type =="NIGHTS":
if specials_nights < (element.minimum_stay * int(nights/element.minimum_stay)):
discount = element.nights_off_discount(Decimal(cost_of_rooms))
print(discount)
specials_nights += 1
else:
discount = 0
elif element.discount_type =="FLAT":
discount = Decimal(element.pay_days)
else:
discount = element.discount(1,Decimal(cost_of_rooms),adults,children,no_of_rooms)
cost_of_rooms = Decimal(cost_of_rooms)-Decimal(discount)
price_instance= math.ceil((Decimal(price_instance) * Decimal(ex.rate))*100)/100
cost_of_rooms = math.ceil((Decimal(cost_of_rooms) * Decimal(ex.rate))*100)/100
discount_recived =Decimal(price_instance)-Decimal(cost_of_rooms)
newli.append({'room': room_instance, 'display_order':room_filter.display_order, 'rm': room_filter, 'date': date_instance, 'quantity':av['quantity'], 'price':int(price_instance),'error':True,'discount':discount_recived,'sp_name':element.name,'sp_description':element.description,'sp_start':element.start,'sp_end':element.end,'count_sp':specail_list})
discount_count.append({'room':room_instance,'normal_rate':price_instance,'discount':discount_recived})
except Exception:
try:
price_instance = math.ceil((Decimal(price_instance) * Decimal(ex.rate))*100)/100
cost_of_rooms = math.ceil((Decimal(cost_of_rooms) * Decimal(ex.rate))*100)/100
except:
pass
discount_recived =Decimal(price_instance)-Decimal(cost_of_rooms)
newli.append({'room': room_instance, 'display_order':room_filter.display_order, 'rm': room_filter, 'date': date_instance, 'quantity':av['quantity'], 'price': int(price_instance),'error':True})
discount_count.append({'room':room_instance,'normal_rate':price_instance,'discount':discount_recived})
newlist = sorted(newli, key=itemgetter('quantity'))
шаблон
{% if rooms.discount_percent > 0 or rooms.sp_name %}
{% for i in rooms.sp_name|slice:"2" %}
<div class="room-plan row ">
<input id="roomid_{{rooms.rm.id}}" type="checkbox" class="room_id" name ="select_room" value="{{rooms.rm.id}}" >
<span class="plan-title" id="sp_{{rooms.rm.id}}">{% if rooms.sp_name %}{{rooms.sp_name}}{% else %}{{rooms.discount_percent}}% Discount{% endif %}</span>
<a class="link" data-toggle="modal" data-target="#discount_{{rooms.rm.id}}"> Rate Details</a>
<span class="cost" id="{{rooms.rm.id}}">
{{current_symbol}}{{rooms.discountprice}}
</span>
<span class="per">per {{rooms.rm.rate_based_on}}</span>
</div>
{% endfor %}
{% endif %}
On Мой шаблон возвращает два элемента, но оба они отображают первый элемент из моего набора запросов:
specail_list = Special.objects.filter(promotion=False, start__lte=date_instance, minimum_stay__lte=nights, object_id=room_filter.id, end__gte=date_instance, is_active=True, member_deal=False)
Примечание: я обновил свой код, но все еще не работает, он не отображает элементы из specail_list в моем шаблоне