rest - Convert a string to another Python class -
is there anyway create class model?
for example, have model.py, 1 of class inside contains:
class customers(ndb.model): lastname = ndb.stringproperty() firstname = ndb.stringproperty() license = ndb.stringproperty() birthdate = ndb.dateproperty() remarks = ndb.textproperty()
i know can models using dir(model)
, , outputs like:
['customers', 'customeraddresses','whatever','__builtins__', '__doc__', '__file__', '__name__', '__package__', 'ndb']
however, there way can use these string inside dir(model)
automatically generate class, like:
class restcustomers(webapp2.requesthandler): #some code gets model class attributes , displays json string customers = # customer attributes model self.response.headers['content-type'] = "application/json" self.response.write(json.dumps(customers))
i'm not sure if possible, kind of way javascript works, wherein like
var models = dir(models); // array var class = "rest"+models[0];
or that...
try this:
from google.appengine.ext.ndb import metadata class restcustomers(webapp2.requesthandler): customers = metadata.get_properties_of_kind(customers) self.response.headers['content-type'] = "application/json" self.response.write(json.dumps(customers))
for more information, see documentation metadata. not sure how get_properties_of_kind
expects kind
argument try out.
Comments
Post a Comment