I also used the multiple select field found on 
http://www.djangosnippets.org/snippets/1200/
with success, until I updated Django to the 1.2 beta release. It now
longer works, always giving the validation error. I have no clue how
to fix this, so I was hoping you found the answer to your problem and
can share it?

I have a tuple with (string, not integer) choices, and want to show
the user a multiple select field. The choices should be saved as a
comma separated string in the database.

Cheers,
Kevin

On Apr 3, 5:30 pm, ben <ben.k...@gmail.com> wrote:
> Either I don't understand how CheckboxSelectMultiple works or there is
> a bug in Django 1.2. I have tried the following custom multi select
> fields I have found around the web.
>
> http://www.djangosnippets.org/snippets/1200/http://www.davidcramer.net/code/181/custom-fields-in-django.html
>
> Out of desperation I tried using a ManyToMany field and all produce
> the same validation error when used with either CheckboxSelectMultiple
> or SelectMultiple.
>
> 'Select a valid choice. [u'1', u'2', u'3', u'4'] is not one of the
> available choices.'
>
> This happens regardless of the number of choices, types of the choices
> tuple values, or the model field type.
>
> Can anyone point me to an example that demonstrates how to properly
> use these fields.
>
> Thanks,
> Ben
>
> On Apr 2, 5:19 pm, Bill Freeman <ke1g...@gmail.com> wrote:
>
>
>
> > I know that I used (some revision of) that snippet a while back.
>
> > Realize that what it stores is a string, containing digits and commas.
>
> > The to_python and get_db_prep_value methods are responsible for
> > converting between that database single string and a list of strings,
> > not integers.  You can use any string (that doesn't contain comma) to
> > represent a choice (db value).  I had two character ID flags (easier to
> > read in pgadmin).  It did work, but I forget the details (I eventually went
> > to multi to multi and the one end of many to one relationships).  So I
> > expect that the DB side of your choice tuples must be strings.
>
> > Bill
>
> > On Fri, Apr 2, 2010 at 3:37 PM, ben <ben.k...@gmail.com> wrote:
> > > Sorry. I pasted code that I was experimenting with. I thought maybe
> > > the validation code was looking for strings because that is what the
> > > error code said it was looking for. Before that I had been using
> > > integers and that doesn't seem to work either. I am wondering if this
> > > is a bug in Django 1.2. I hunted around on Django snippets as Bill
> > > Freeman suggested and found the following 
> > > codehttp://www.djangosnippets.org/snippets/1200/
> > > for a custom multiple selection field.
>
> > > I inserted it into my app and it doesn't want to validate the
> > > selection either. In fact it returns a validation error message
> > > similar to what I received from CommaSeperatedIntegerField and
> > > CheckboxSelectMultiple. "Value [u'1'] is not a valid choice."
>
> > > Not sure what is going on. Any insights would be appreciated.
>
> > > On Apr 2, 3:06 pm, orokusaki <flashdesign...@gmail.com> wrote:
> > >> The problem is that you're using '1' instead of 1. The comma
> > >> separated integer list is expecting integers not strings. The reason
> > >> you're seeing u'1' is because it's being turned from a string to a
> > >> unicode object.
>
> > >> Try this instead:
>
> > >> SOME_CHOICES =  ((1, 'ch1'),(2, 'ch2'), (3, 'ch3'),(4, 'ch4'))
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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