On Fri, Feb 4, 2011 at 11:07 AM, Marc Aymerich <[email protected]> wrote:
> Hi
> In some choices widgets I want to represent null values as u'No
> period' instead of u'--------'
>
> I try with:
>
> PERIOD_CHOICES = getattr(settings, 'PERIOD_CHOICES',
> ((None,
> ugettext('No Period')),
> (DAILY,
> ugettext('Daily')),
> (MONTHLY,
> ugettext('Monthly')),
> (ANUAL,
> ugettext('Anual')),
> ))
> period = models.CharField(max_length=1,
> choices=settings.PERIOD_CHOICES, null=True)
>
> But when I choose "No Period" I get this form validation error: Value
> u'None' is not a valid choice.
>
> Any idea?
> Thanks!
form.Field doesn't take null as an option, you want required[1]:
"""
By default, each Field class assumes the value is required, so if you
pass an empty value -- either None or the empty string ("") -- then
clean() will raise a ValidationError exception:
"""
Cheers
Tom
[1] http://docs.djangoproject.com/en/1.2/ref/forms/fields/#required
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.