我正在尝试为Canteen创建一个菜单,该菜单中的admin正在更新/添加产品名称和价格。但是,我如何检索客户订购的商品?
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Item Name</th>
<th scope="col">Item Price</th>
<th scope="col">Item Type</th>
<th scope="col">Quantity</th>
</tr>
</thead>
{% for temp in food_dict %}
<tr>
<td>{{ temp.food_name }}</td>
<td>{{ temp.food_price }}</td>
<td>{{ temp.type }}</td>
<td>
<input type="button" onclick="dec({{ forloop.counter }})" class="btn btn-light" value="-"/>
<input type="button" id="{{ forloop.counter }}" name="temp.food_name" class="btn btn-light" value="0"/>
<input type="button" onclick="inc({{ forloop.counter }})" class="btn btn-light" value="+" />
{{ temp.food_name }}
</td>
</tr>`enter code here`
{% endfor %}
{% endif %}
</table>
这是models.py,管理员在其中添加食物
class Food_items(models.Model):
food_name = models.CharField(max_length=264,unique=True)
food_price = models.CharField(max_length=264)
type = models.CharField(max_length = 6,choices =
type_choices,default='tiffin')
def __str__(self):
return self.food_name
这是views.py
def viewmenu(request):
food_list = Food_items.objects.order_by('food_name')
food_dict = {'food_dict':food_list,'v':1}
return render(request,'first_app/viewmenu.html',context=food_dict)