[Zope3-Users] default values in Choice fields

Lorenzo Gil Sanchez lgs at sicem.biz
Thu Feb 9 07:48:52 EST 2006


Hi

I have a field in my schema like this:

fruit = Choice(title=u'Fruit',
                description=u'An example choice field',
                default=None,
                required=True,
                values=('Apple', 'Orange', 'Banana', 'Strawberry'))

I want to specify a default value for this field but I want it to be 
from the list of values.

Is there a preferred way to do it or just do something like this:

fruit_values = ('Apple', 'Orange', 'Banana', 'Strawberry')

fruit = Choice(title=u'Fruit',
                description=u'An example choice field',
                default=fruit_values[0],
                required=True,
                values=fruit_values)

In the implementation of my content type, do I have to write 'Apple' for 
the default value again or there is another way? I want to avoid 
duplicating hardwired names.

Sorry if this is a dumb question

Thanks in advance

Lorenzo


More information about the Zope3-users mailing list