我有这样的代码,它不会打印任何内容:
from google.cloud import datastore
client = datastore.Client()
query = client.query(kind='Kind')
query.add_filter('status', '=', 'new')
results = query.fetch()
for result in results:
print result
当我注释query.add_filter('status', '=', 'new')
行时,它会按预期打印所有实体。
我的index.yaml文件是:
indexes:
- kind: Kind
properties:
- name: increment
- name: status
数据存储仪表板上的状态为“正在投放”
我使用App Engine的以下代码创建实体:
class Kind(ndb.Model):
json = ndb.TextProperty()
status = ndb.TextProperty(indexed=True)
increment = ndb.IntegerProperty()
created = ndb.DateTimeProperty(auto_now_add=True)
class MainPage(webapp2.RequestHandler):
@ndb.toplevel
def post(self):
parajson = self.request.get("json")
parastatus = self.request.get("status")
paraincrementtmp = self.request.get("id")
print paraincrementtmp
paraincrement = int(paraincrementtmp)
#print parajson
write = Kind(json = parajson,
status = parastatus,
increment = paraincrement)
key = write.put()
如何在第一个代码片段中使add_filter部分起作用?