Python 计算电子商务网站的所有订单项目
我正在建立一个食品配送网站。我目前已经全部设置好了,但我正在构建一个管理页面,该页面汇总了每种食物的订单总量 “位置”属性有6个可能的下降点。我有三次送货上门。我想计算每个交货时间/地点的所有单个食品项目。我不知道如何使用django实现这一点 最好的方法是什么 我将实际的“订单”模型与“订单项”模型分开 订单项:Python 计算电子商务网站的所有订单项目,python,django,model,one-to-many,counter,Python,Django,Model,One To Many,Counter,我正在建立一个食品配送网站。我目前已经全部设置好了,但我正在构建一个管理页面,该页面汇总了每种食物的订单总量 “位置”属性有6个可能的下降点。我有三次送货上门。我想计算每个交货时间/地点的所有单个食品项目。我不知道如何使用django实现这一点 最好的方法是什么 我将实际的“订单”模型与“订单项”模型分开 订单项: class OrderItem(models.Model): product = models.ForeignKey(Food) quantity = models.
class OrderItem(models.Model):
product = models.ForeignKey(Food)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=7,decimal_places=2)
order = models.ForeignKey(Order)
尝试:
class OrderItem(models.Model):
product = models.ForeignKey(Food)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=7,decimal_places=2)
order = models.ForeignKey(Order)
orders = orders.annotate(num_items=Count('orderitem_set'))
for order in orders:
print order.pk, order.num_items