python - 检查 Google App Engine 模型中的属性类型

标签 python google-app-engine

是否可以检测模型属性的类型?

class MODULENAME(db.Model):
    id1 = db.StringProperty()
    id2 = db.StringProperty()
    id3 = db.StringProperty()
    property1 = db.StringProperty()
    property2 = db.StringProperty()
    createdate = db.DateProperty(auto_now_add=True)
    changedate = db.DateProperty(auto_now_add=True)
    isactive = db.BooleanProperty()

如何测试“id3”是 int、float 还是 string?

到目前为止,我了解到模型有一个名为“_all_propertie”的方法,该方法返回一个列表,其中包含我在模型中创建的所有属性。现在我想检查属性类型,以便我可以使用正确的 html 输入类型自动创建表单,并且如果我更改属性类型,HTML 将自动更改。

这有意义还是我偏离了轨道?

/迈克尔

最佳答案

工作代码:

from google.appengine.ext import db

class MODULENAME(db.Model):
    id1 = db.StringProperty()
    id2 = db.StringProperty()
    id3 = db.DateProperty()
    property1 = db.StringProperty()
    createdate = db.DateProperty(auto_now_add=True)
    changedate = db.DateProperty(auto_now_add=True)
    isactive = db.BooleanProperty()

m = MODULENAME()
plist = m.properties()
for p in plist:
    print "%s: %s" % (p, str(plist[p]))

谢谢 Daniel Roseman 和 Nick Johnson 提供的线索。

关于python - 检查 Google App Engine 模型中的属性类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7483457/

相关文章:

python - LSTM - 对部分序列进行预测

python - 谷歌应用引擎 : how to send html using send_mail

python - Python Google App Engine 中的密码重置 token

python - 如何使用@classmethod将实体转换为消息

python - 使用 Pandas Excelwriter 写入 StringIO 对象?

python - 用于可视化循环 ETA 的进度条

google-app-engine - Google App Engine 自定义域 - Go 中的路由

java - Google App Engine (Java) - JDO PersistenceManager makePersistentAll 速度减慢

python - 如何使用大量 bool 属性创建高效的 Google-App-Engine 架构

python - 在 Python 中使用 XML namespace 时,如何使我的代码更具可读性和 DRYer?