在 GAE 数据存储中对多个选择进行建模

发布于 2025-01-07 12:58:15 字数 413 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾兮 2025-01-14 12:58:15

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文