On Thu, Mar 12, 2009 at 5:33 AM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Thu, 2009-03-12 at 02:55 -0700, K*K wrote:
> > I got a strange problem.
> >
> > I specify a ChoiceField as SelectMultiple widget but got problem in
> > validation.
> >
> > Can django ChoiceFIeld support valid with a List ? or how can I do
> > it ?
> >
> > The source code is following:
> >
> > # Source code of forms.py:
> >
> > COMPONENTS_CHOICE = []
> > for component in get_components():
> >     COMPONENTS_CHOICE.append((component.id, component.name))
>
> [...]
> > # Response Page:
> > * components_ids
> > -- Select a valid choice. [u'23507'] is not one of the available
> > choices.
>
> If you have a look at your choices list, I think you'll see that the
> string "23507" is, indeed, not one of the valid choices. It looks like
> all your choice values are integers and u"23507" is not to equal to the
> integer 23507, for example. You'll need to convert your component.id
> values to strings before putting them in the choices list.
>
> Regards,
> Malcolm
>
>
>
> >
>
Alternatively you could use a TypedChoiceField(which may not be
documented).  It looks like you're working with models here so it may be
easier for you to just use a ModelChoiceField, which handles these issues
for you.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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