Another example, on top of the example he put in his original post?

A sequence is a generic python term for a collection of objects that
can be iterated through. So a list (or array, if you don't grok the
lingo) is a sequence, so is a tuple, so is a string - its a sequence
of characters.

All these things are sequences:

[ 'a', 'b', 'c', ]
( 'a', 'b', 'c', )
'abc'

and they all have identical output in the following code:

for obj in seq:
  print obj

In your question, you were passing the string 'choice753' as the
initial value for your multi select widget. Multi select widgets want
a sequence as an initial value, with each value in the sequence
corresponding to a selected element (so you were saying 'the selected
elements are those with values 'c', 'h', 'o', 'i', 'c', 'e', '7', '5'
or '3'). You should have been passing a sequence of selected choices,
so either [ 'choice753', ] or ( 'choice753', ) (note the trailing
commas).

If you look closely at Bruno's reply, this is exactly what he told you.

Cheers

Tom

On Fri, Jun 18, 2010 at 3:13 PM, Jeff Green <jeffhg2...@gmail.com> wrote:
> Can you clarify what you mean by sequence. It would be appreciated if you
> can provide me of an example which might help me to understand how to
> implement it.
>
> Thanks,
> Jeff
>
> On Fri, Jun 18, 2010 at 8:44 AM, bruno desthuilliers
> <bruno.desthuilli...@gmail.com> wrote:
>>
>>
>> On 18 juin, 15:03, Jeff Green <jeffhg2...@gmail.com> wrote:
>> > I have been trying unsuccessfully to select the initial value of a
>> > multi select drop down.
>> >
>> > I was wondering what I am missing as to why this does not seem to be
>> > working.
>> >
>> > Here is a snippet of my code
>> >
>> > self.fields[config.ConfigurationName] = forms.MultipleChoiceField(
>> >                                         choices=choicelist,
>> >                                         initial='choice753',
>> >                                         required=False)
>> >
>>
>> A MultipleChoiceField works with a sequence, not with a single
>> element, so passing the appropriate sequence as initial value might
>> help.
>>
>> self.fields[config.ConfigurationName] = forms.MultipleChoiceField(
>>                                          choices=choicelist,
>>                                          initial=['choice753'], # use
>> a list here
>>                                          required=False)
>>
>>
>>
>> PS 1 : not tested but IIRC that's how I always initialised these
>> fields.
>>
>> PS 2 : In case you wonder why it didn't raise an exception with a
>> single string as initial value, remember that strings are sequences
>> too - so what the MultipleChoiceField tried to use was in fact ['c',
>> 'h', 'o', 'i', 'c', 'e', '7', '5', '3'] !-)
>>
>> HTH
>>
>> --
>> 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.
>

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