【发布时间】:2021-06-10 13:47:48
【问题描述】:
我有以下代码:
obj = Products.objects.filter(dump__product_name = 'ABC, dump__product_color = 'black').values()
new_price = [100, 200, 300]
for item in range(len(obj)):
obj[item]['price'] -= new_price[item]
Products.objects.filter(dump__product_name = 'ABC, dump__product_color = 'black').bulk_update(obj, ['price'])
但我得到了错误,Exception inside application: 'dict' has no attribute 'pk'
obj的值是这样的:
<QuerySet [{'id': 1, 'product_name': 'Acer - Laptop', 'price': 350},
{'id': 1, 'product_name': 'Dell - Laptop', 'price': 450},
{'id': 1, 'product_name': 'Samsung- Laptop', 'price': 650}]>
我无法弄清楚代码有什么问题。任何帮助将非常感激。提前非常感谢
【问题讨论】:
-
这是许多个原因之一,不使用
.values()。
标签: python-3.x django django-models bulkupdate