谷歌应用程序引擎中的选择属性

发布于 2024-07-19 14:33:37 字数 654 浏览 4 评论 0原文

平台: django 1.0,google app engine,app-engine-patch,python 2.5.4

我正在尝试使用choices属性,因为我一直在django网站中使用

STATUS_CHOICES = ( (1, _('Yet To Start')), (2, _('Running')), (3, _('Paused')), (4, _('Completed')), (5, _('Cancelled')), (6, _('Error')),)

class Campaign(db.Model):
    name = db.TextProperty()
    status = db.IntegerProperty(choices=STATUS_CHOICES,default=2)

,因为我已经转移到app-engine,我看不到这是工作...

我正在得到一个

错误值错误

财产状况为3; 必须是其中之一 ((1, u'尚未开始'), (2, u'正在运行'), (3, u'暂停'), (4, u'已完成'), (5, u'已取消'), (6, u'错误'))

我该如何解决这个问题?

platform: django 1.0, google app engine, app-engine-patch , python 2.5.4

i am tring to use the choices attribute as i always have been using in django website

STATUS_CHOICES = ( (1, _('Yet To Start')), (2, _('Running')), (3, _('Paused')), (4, _('Completed')), (5, _('Cancelled')), (6, _('Error')),)

class Campaign(db.Model):
    name = db.TextProperty()
    status = db.IntegerProperty(choices=STATUS_CHOICES,default=2)

now as i have moved to app-engine i dont see this is working...

i am getting a

BadValueError

Property status is 3; must be one of
((1, u'Yet To Start'), (2,
u'Running'), (3, u'Paused'), (4,
u'Completed'), (5, u'Cancelled'), (6,
u'Error'))

how shud i go about this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

月朦胧 2024-07-26 14:33:38

这是一个已记录的问题,无法解决。 简单地说,使用 GAE 时不能这样做。

Guido 在关闭上述票证时说了以下内容:

非常抱歉,但我必须将其视为无效而关闭。

db.Property 类的 choice 参数的 App Engine 定义为
与 Django 的定义不同。 看
http://code.google.com/appengine/docs/datastore/ propertyclass.html#属性

我意识到,当您尝试从以下位置创建表单时,这可能会导致问题
模型,但解决方案是使用自定义小部件覆盖表单字段并
将所需选项的列表传递给小部件。 (有一个这样的例子
Rietveld,在 codereview/views.py 中,SettingForm 类。)

This is a documented problem that will not be resolved. Simply put, you can't do this when using GAE.

Guido says the following when closing the above ticket:

I'm very sorry, but I have to close this as invalid.

The App Engine definition of the choices parameter to the db.Property class is
different from the Django definition. See
http://code.google.com/appengine/docs/datastore/propertyclass.html#Property

I realize that this may cause problems when you're trying to create a form from the
model, but the solution is to override the form field using a custom widget and
passing the list of desired choices to the widget. (There's an example of this in
Rietveld, in codereview/views.py, class SettingForm.)

半﹌身腐败 2024-07-26 14:33:38

正如 Paolo 所说,这不是选择参数在 App Engine 模型中的工作方式。 不过,完全有可能编写您自己的自定义属性,使其按照您想要的方式运行。 以下是食谱中类似的示例:EnumProperty

As Paolo says, this is not how the choices parameter works in App Engine models. It's perfectly possible to write your own custom Properties that behave however you want, though. Here's an example from the cookbook of one that's similar: EnumProperty.

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