queries = [query for query in QueryHistory.query().order(-QueryHistory.date)]
if(len(queries) > constants.QUERY_LIMIT_SIZE):
que = queries[constants.QUERY_LIMIT_SIZE:]
list_of_keys = que.fetch(keys_only = True)
ndb.delete_multi(list_of_keys)
我收到AttributeError:从数据存储区删除数据时,“ list”对象没有属性“ fetch”错误。如果有人有解决方案,请发表评论。
答案 0 :(得分:1)
您的que
是一个查询列表,您需要在列表的每个成员而不是列表本身上调用.fetch()
。试试这个:
queries = [query for query in QueryHistory.query().order(-QueryHistory.date)]
if(len(queries) > constants.QUERY_LIMIT_SIZE):
que = queries[constants.QUERY_LIMIT_SIZE:]
for query in que:
list_of_keys = query.fetch(keys_only = True)
ndb.delete_multi(list_of_keys)