モデル用に別のクラスを作成する方法はありますか?
たとえば、内部のクラスの 1 つに含まれる model.py があります。
class Customers(ndb.Model):
lastname = ndb.StringProperty()
firstname = ndb.StringProperty()
license = ndb.StringProperty()
birthdate = ndb.DateProperty()
remarks = ndb.TextProperty()
を使用してモデルを取得できることはわかってdir(model)
おり、次のような出力が得られます。
['Customers', 'CustomerAddresses','Whatever','__builtins__', '__doc__', '__file__', '__name__', '__package__', 'ndb']
ただし、これらの文字列を内部で使用して、次dir(model)
のような別のクラスを自動的に生成する方法はありますか?
class RestCustomers(webapp2.RequestHandler):
#some code that gets the model class attributes and displays the json string
customers = # customer attributes from model
self.response.headers['Content-Type'] = "application/json"
self.response.write(json.dumps(customers))
それが可能かどうかはわかりませんが、javascriptの仕組みのようなもので、次のように言います
var models = dir(models); // which is an array
var class = "Rest"+models[0];
またはそのようなもの...