我一直在尝试使用 django 获取吃的比萨饼总数
我的模型是这样的:
class pizza_total_eated(Model.models):
user #fk to users
pizza #fk to pizzas
total_eated #total number of `pizza` eaten
"""
+------+-------+-------+
| user | pizza | total |
+------+-------+-------+
| 1 | 1 | 5 |
| 1 | 2 | 6 |
| 2 | 3 | 4 |
"""
这存储了用户吃的某种类型的比萨饼的总数。基本上我想检索用户吃披萨的总数
当我只有一个披萨时,吃的总数很容易:
pizza_total = pizza_total_eated.objects.filter(Pizza = 1)
for user in pizza_total:
user.total_eated
但是我怎么能为每个用户做这个=>每个披萨
for user in pizza_total
for pizza in user.pizza
pizza.total_eated #user 1 -> pizza 1 so total_eated = 5