choice property in google app engine

≡放荡痞女 提交于 2019-12-01 15:10:46

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!