【发布时间】:2016-01-01 23:09:17
【问题描述】:
我只需要为我自己的应用程序解决这个问题,所以在这里重新发布答案。
【问题讨论】:
我只需要为我自己的应用程序解决这个问题,所以在这里重新发布答案。
【问题讨论】:
自从提出并回答这个问题已经过去了。现在有一个更简单的方法。
见http://code.google.com/appengine/docs/python/datastore/metadataqueries.html
q = Kind.all()
for kind in q.fetch(100):
print kind.kind_name
【讨论】:
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)
参考:http://groups.google.com/group/google-appengine/browse_thread/thread/f2e7568040c015ff
【讨论】:
值得注意的是,此答案适用于较旧的db api。新的ndb api 有另一种方法来获取此处列出的所有Kind https://cloud.google.com/appengine/docs/python/ndb/metadata#get_kinds
【讨论】: