Google app engine 如何在数据存储中列出种类?
我只是需要在我自己的应用程序中解决这个问题,所以在这里重新发布答案Google app engine 如何在数据存储中列出种类?,google-app-engine,Google App Engine,我只是需要在我自己的应用程序中解决这个问题,所以在这里重新发布答案 def GetSchemaKinds(): """Returns the list of kinds for this app.""" class KindStatError(Exception): """Unable to find kind stats.""" from google.appengine.ext.db import stats global_stat = sta
def GetSchemaKinds():
"""Returns the list of kinds for this app."""
class KindStatError(Exception):
"""Unable to find kind stats."""
from google.appengine.ext.db import stats
global_stat = stats.GlobalStat.all().get()
if not global_stat:
raise KindStatError()
timestamp = global_stat.timestamp
kind_stat = stats.KindStat.all().filter(
"timestamp =", timestamp).fetch(1000)
kind_list = [stat.kind_name for stat in kind_stat
if stat.kind_name and not stat.kind_name.startswith('__')]
kind_set = set(kind_list)
return list(kind_set)
参考资料:自询问并回答此问题以来,时间已过。现在有一个更简单的方法 看
值得注意的是,这个答案适用于较旧的
db
api。新的ndb
api有另一种方法来获取这里列出的所有Kind
q = Kind.all()
for kind in q.fetch(100):
print kind.kind_name