python – Google App Engine中模型的默认值
发布时间:2020-11-18 11:21:11 所属栏目:Python 来源:互联网
导读:是否可以为模型设置默认值?例如,从Appengine Documentation中考虑此模型 from google.appengine.ext import dbclass Pet(db.Model): name = db.StringProperty(required=True) type = db.StringProperty(required=True, choices
是否可以为模型设置默认值?例如,从Appengine Documentation中考虑此模型 from google.appengine.ext import db class Pet(db.Model): name = db.StringProperty(required=True) type = db.StringProperty(required=True,choices=set(["cat","dog","bird"])) birthdate = db.DateProperty() weight_in_pounds = db.IntegerProperty() spayed_or_neutered = db.BooleanProperty() owner = db.UserProperty(required=True) 我想将name的默认值设置为“Unnamed Pet”,因此如果用户不提供,则采用默认值.这可能吗? PS:我希望这可以在模型类Pet本身中完成 解决方法使用默认属性,例如class Pet(db.Model): name = db.StringProperty(required=True,default="(unnamed)") (编辑:百色站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- Python ConfigParser检查Section和Key Value的存
- python – 使用scikit-learn(sklearn),如何处理线
- python – Jinja2中的宏递归
- python – 基本的openGL,顶点缓冲区和pyglet
- python – hashlib.md5()TypeError:Unicode对象
- Python使用urllib2模块实现断点续传下载的方法
- 基于wxpython开发的简单gui计算器实例
- python – 计算两个numpy数组之间相交值的有效方
- Python使用metaclass实现Singleton模式的方法
- python – joblib和pickle的不同用例是什么?
热点阅读