How can I get the ndb.Model when my only input is an ndb.Query?

前端 未结 2 639
醉梦人生
醉梦人生 2020-12-21 14:00

Let\'s say there is ndb.Model that looks like this:

class Foo(ndb.Model):
  bar = ndb.StringProperty()

My question is, if my o

2条回答
  •  轮回少年
    2020-12-21 14:26

    I use this code to find the model class if you have the kind name:

    model_module = KIND_MODULES(kind_name)
    mod = __import__(model_module, globals(), locals(), [kind_name], -1)
    model_class = getattr(mod, kind_name)
    

    The KIND Modules dict holds the modules to import the models from:

    KIND_MODULES = { 'Users' : 'models', 'Comments' : 'models', 'Cities' : 'examples.models' }
    

提交回复
热议问题