Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 如何在数据存储中列出种类?_Google App Engine - Fatal编程技术网

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