Google App Engine 中模型的默认值
是否可以为模型设置默认值?例如,考虑Appengine文档中的这个模型,
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
本身中完成
Is it possible to set default values for models ? For example consider this model from 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)
I want to set the default value of name
to be "Unnamed Pet", so if the user doesn't supply it , The default values taken . So is this possible ?
PS : I want this to be done in the model class Pet
itself
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用默认属性,例如
Use the default attribute, e.g.