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 code 
> http://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 at 
> http://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