我正在建立一個網站,大學生可以訂購送貨食物。關於我們網站的一個特殊的屬性是客戶必須選擇預設的交貨時間。例如,我們在晚上7點,晚上10點和午夜有所下降。sqllite讀/寫隊列與Django的關注
有關食物的所有信息都是靜態的(即價格,描述,名稱),但該特定放置時間的剩餘數量除外。
很明顯,我不想硬編碼我的菜單頁上的所有食品的HTML,所以我寫了一個forloop在HTML模板。所以我需要在我的模型中的某處存儲剩餘的特定時間的數量。唯一的問題是,如果我使用相同的變量將剩餘的數量傳輸到我的模板,我會發出錯誤的信息,如果有很多人同時訪問菜單頁面,我會感到害怕。
例如,假設下午7點下降剩餘10個捲餅。下午10點有40個捲餅。如果有人有比其他客戶更快的網絡,是否有機會顯示剩餘的錯誤數量?
你們會如何解決這個問題? 我基本上需要一種方式來告訴我的模板在特定時間剩餘的數量。並使用我現在的解決方案,並不會讓我感到安心。特別是如果很多人要同時訪問該網站。
view.py
orders = OrderItem.objects.filter(date__range=[now - timedelta(hours=20), now]).filter(time=hour)
steak_and_egg = 0
queso = 0
for food in orders:
if food.product.name == "Steak and Egg Burrito":
steak_and_egg = steak_and_egg + food.quantity
elif food.product.name == "Queso Burrito":
queso = queso + food.quantity
#if burritos are sold out, then tell template not to display "buy" link
quantity_steak_and_egg = max_cotixan_steak_and_egg - steak_and_egg
quantity_queso = max_cotixan_queso - queso
#psuedocode
steakandegg.quantity_remaining = quantity_steak_and_egg
queso.quantity_remaining = quantity_queso
HTML:
{% for item in food %}
<div id="food_set">
<img src="{{item.photo_menu.url}}" alt="" id="thumbnail photo" />
<div style='overflow:hidden'>
<p id="food_name">{{item.name}}</p>
<p id="price">${{item.price}}</p>
</div>
<p id="food_restaurant">By {{item.restaurant}}</p>
<div id="food_footer">
<img src="{{MEDIA_URL}}/images/order_dots.png" alt="" id="order_dots" />
<a id ="order_button" href="{{item.slug}}"></a>
<p id="quantity_remaining">{{item.quantity_remaining}} left</p>
</div><!-- end food_footer-->
</div><!-- end food_set-->
你是一個紳士和學者 – anc1revv