在 GAE 数据存储中对多个选择进行建模
App Engine 文档提供了如何强制执行数据存储实体属性的一组选择的示例:
from google.appengine.ext import db
class Pet(db.Model):
type = db.StringProperty(required=True, choices=set(["cat", "dog", "bird"]))
我希望强制执行一组可能的值,但允许选择多个值。我遇到了 StringListProperty
属性类,但我不知道强制执行一组可能的选择。
除了明确实施架构之外,我希望能够通过数据存储管理界面中的复选框修改实体。现在,如果我使用StringListProperty
,则无法编辑数据存储管理中的相应字段。我所描述的可能吗?
The App Engine documentation gives an example of how a set of choices for a datastore entity's property can be enforced:
from google.appengine.ext import db
class Pet(db.Model):
type = db.StringProperty(required=True, choices=set(["cat", "dog", "bird"]))
I would like enforce a set of possible values, but allow for multiple values to be selected. I came across the StringListProperty
property class, but I don't know to enforce a set of possible choices.
Other than clarity enforcing a schema, what I'm hoping for is to be able to modify the entities via checkboxes in the datastore admin interface. Right now, if I use StringListProperty
, the corresponding field in the datastore admin cannot be edited. Is what I'm describing possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ndb (http://code.google.com/p/appengine-ndb-experiment/)
将在 GAE 1.6.3 中正式提供(请参阅 https://plus.google.com/111042085517496880918/posts/9uJXHj8iiqV)
您可以为该属性编写一个验证器函数,请参阅
http://code.google.com /p/appengine-ndb-experiment/source/browse/ndb/model.py#112
ndb (http://code.google.com/p/appengine-ndb-experiment/)
will be officially available in GAE 1.6.3 (see https://plus.google.com/111042085517496880918/posts/9uJXHj8iiqV)
You could write a validator function for the property, see
http://code.google.com/p/appengine-ndb-experiment/source/browse/ndb/model.py#112