Let\'s say there is ndb.Model
that looks like this:
class Foo(ndb.Model):
bar = ndb.StringProperty()
My question is, if my o
After you have imported code with this model definition, the list ndb.Model._kind_map
should contain it. Here is the magic:
def query_to_model(query):
return ndb.Model._kind_map[query.name]
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' }