google应用引擎中的选择属性 [英] choice property in google app engine
问题描述
平台:django 1.0,Google应用引擎,app-engine-patch,python 2.5.4
platform: django 1.0, google app engine, app-engine-patch , python 2.5.4
我正在使用选择属性,因为我一直都是在django网站中使用
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...
我得到一个
BadValueError
BadValueError
属性状态为3;必须是
之一((1,u'Yet To Start'),(2,
u'Running'),(3,u'Paused'),(4,
u '完成'),(5,u'Cancelled'),(6,
u'Error'))
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'))
如何解决这个问题呢?
推荐答案
这是一个无法解决的文档问题。简单地说,在使用GAE时,您不能这样做。
This is a documented problem that will not be resolved. Simply put, you can't do this when using GAE.
Guido在关闭上述票时说以下内容:
Guido says the following when closing the above ticket:
我很抱歉,但我必须将其关闭为无效。
I'm very sorry, but I have to close this as invalid.
App Engine定义的db.Property类是
,与Django定义不同。请参阅
http://code.google.com/appengine /docs/datastore/propertyclass.html#Property
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
我意识到,当您尝试从$ b $创建表单时,可能会导致问题b模型,但解决方案是使用自定义窗口小部件覆盖表单域,
将所需选项列表传递给窗口小部件。 (在
Rietveld中有一个例子,在codereview / views.py,类SettingForm。)
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.)
这篇关于google应用引擎中的选择属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!