s/left/leave/
sorry fot the double post.

On Fri, Feb 4, 2011 at 11:37 AM, Marcos Moyano <marcosmoy...@gmail.com>wrote:

> Remove (None, "No Period") from your choices and left the required=False on
> your form field. That should work.
>
> Rgds,
> Marcos
>
>
> On Fri, Feb 4, 2011 at 11:31 AM, Marc Aymerich <glicer...@gmail.com>wrote:
>
>> On Fri, Feb 4, 2011 at 12:12 PM, Tom Evans <tevans...@googlemail.com>
>> wrote:
>> > On Fri, Feb 4, 2011 at 11:07 AM, Marc Aymerich <glicer...@gmail.com>
>> 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
>>
>>
>> Hi Tom,
>> I override the default admin form with this:
>>
>> class MonitorAdminForm(ModelForm):
>>    class Meta:
>>        model = Monitor
>>    period = forms.ChoiceField(required=False, choices =
>> settings.PERIOD_CHOICES)
>>
>> Now period has required=False but still raise the validation error:
>> Value u'None' is not a valid choice.
>>
>> What is strange for me is although I put the None value on
>> PERIOD_CHOICES the error seems to say that None is interpreted as a
>> unicode instead of None. Maybe this is the point, if it's, how can I
>> declare a null value in PERIOD_CHOICES definition ?
>>
>> Thanks!
>>
>>
>>
>>
>>
>> --
>> Marc
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Some people, when confronted with a problem, think “I know, I'll use
> regular expressions.” Now they have two problems.
>
> Jamie Zawinski, in comp.emacs.xemacs
>



-- 
Some people, when confronted with a problem, think “I know, I'll use regular
expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to