我一直在尝试向预先存在的字典键添加一个值。该值来自Car
具有名为 的属性的 db.Model price
。
尝试了两个代码块(如下),但得到了 AttributeError: 'GqlQuery' object has no attribute 'price'。
items = {"BE1234":"2","BE1923":"3","BE2032":"1", etc}
------------------------------------------------------------
block 1)
for item in items:
cars = db.GqlQuery('SELECT * FROM Car WHERE item=:1',item)
items[item] = cars.price
------------------------------------------------------------
block 2)
for item in items:
cars = db.GqlQuery('SELECT * FROM Car WHERE item=:1',item)
items.update({item:cars.price})
我想要得到的是:
items = {"BE1234":["2","100"],"BE1923":["31","200"],"BE2032":["19","300"], etc}
更新(最终工作代码)
for item in items:
cars = db.GqlQuery('SELECT * FROM Car WHERE item=:1',item)
for car in cars:
items[item]=[items[item],str(car.price)]