views:

523

answers:

2

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?

+1  A: 

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.)

Paolo Bergantino
A: 

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.

Nick Johnson