class Employee(db.Model):
firstname = db.StringProperty()
lastname = db.StringProperty()
address1 = db.StringProperty()
timezone = db.FloatProperty() #might be -3.5 (can contain fractions)
class TestClassAttributes(webapp.RequestHandler):
"""
Enumerate attributes of a db.Model class
"""
def get(self):
for item in Employee.properties():
self.response.out.write("<br/>" + item)
#for subitem in item.__dict__:
# self.response.out.write("<br/> --" + subitem)
以上将为我提供变量“item”的属性名称列表。我的想法item.__dict__
没有奏效,因为item
它是一个str
. 然后如何显示每个属性的数据字段类型,例如名为db.FloatProperty()
的属性timezone
?
GAE = Google App Engine - 但我确信相同的答案适用于任何课程。
谢谢,尼尔沃尔特斯