Selecting a property in the google engine
platform: django 1.0, google engine, application-engine-patch, python 2.5.4
I am trying to use the select attribute as I have always used it in the 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 when i go to engine app i dont see it working ...
I get
BadValueError
Property state 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 can I solve this problem?
a source to share
This is a documented issue and will not be resolved. Simply put, you cannot do this when using GAE.
Guido talks about closing the above ticket:
I'm sorry, but I have to close this as invalid.
Defining an App Engine pick parameter for a db.Property class other than Django's. See http://code.google.com/appengine/docs/datastore/propertyclass.html#Property
I understand this can cause problems when you are trying to create a form from a model, but the solution is to override the form field with a custom widget and pass the list of desired options to the widget. (Here's an example of this in Rietveld, in codereview / views.py, the SettingForm class.)
a source to share
As Paolo says, this is not how the select parameter works in App Engine models. However, it's entirely possible to write your own custom properties that behave however you want. Here's an example from a cookbook of what looks like: EnumProperty .
a source to share