How to list kinds in datastore?

前端 未结 3 603
我寻月下人不归
我寻月下人不归 2021-01-18 20:44

I just had to figure this out for my own application, so reposting the answer here.

3条回答
  •  -上瘾入骨i
    2021-01-18 21:40

    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) 
    

    Reference: http://groups.google.com/group/google-appengine/browse_thread/thread/f2e7568040c015ff

提交回复
热议问题