如何在GAE Python中获取所有NDB模型名称的列表?
所有NDB模型都是从继承的Python类ndb.Model
。我以为我们可以使用此信息来获取所有模型的名称。
class BK (ndb.Model):
property_1 = ..
我尝试了以下(借来的)代码,但徒劳:
尝试1
logging.info ( [ cls.__name__ for cls in globals()['ndb.Model'].__subclasses__() ] )
它导致错误:
KeyError:“ ndb.Model”
尝试2
logging.info ( [ cls.__name__ for cls in globals()['Model'].__subclasses__() ] )
它导致错误:
KeyError:“模型”
对您来说幸运的是,在这种情况下,它要容易得多:
from google.appengine.ext import ndb
class Test(ndb.Model):
pass
print ndb.Model._kind_map
产生以下输出:
{'Test': Test<>}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句