这是我的GAE数据存储区:
class Search(ndb.Model):
city = ndb.StringProperty()
counter = ndb.IntegerProperty(indexed = True)
date = ndb.DateTimeProperty(auto_now_add=True)
当我运行这段代码时:
keys = Search.query(Search.city == city).fetch()
if (len(keys)==0):
luogo = Search(city = city, counter = 1)
luogo.put()
else:
for key in keys:
luogo_1 = key.get()
luogo_1.counter = luogo_1.counter+1
luogo_1.put()
我的终端说在对象搜索属性获取
中缺少你知道为什么吗?
答案 0 :(得分:1)
答案 1 :(得分:1)
正在运行
keys = Search.query(Search.city == city).fetch()
获取模型实例
的列表所以
for key in keys:
luogo_1 = key.get()
失败,因为实例没有get
方法。
你需要这样做:
keys = Search.query(Search.city == city).fetch(keys_only=True)
获取密钥列表,或将keys
视为实例列表而不是密钥,并省略key.get()
调用。