On Fri, 2009-01-09 at 21:20 -0600, Tolu wrote:
> lol I had originally tried that too. Nothing seems to work! I am thinking my 
> logic might be wrong from the start.

Sorry, I was too fast in my last reply and missed a second error in your
line. Should have read more closely.
[...]
> > On Fri, 2009-01-09 at 20:29 -0600, Tolu wrote:
> >> I tried this. The checkboxes displayed but none of them were checked:
> >>
> >> LOOKING_FOR = (
> >>         ('Friendship', 'Friendship'),
> >>         ('Dating', 'Dating'),
> >>         ('A Relationship', 'A Relationship'),
> >>         ('Networking', 'Networking'),
> >> )
> >>
> >> class ProfileForm(forms.ModelForm):
> >>     lookingfor = forms.MultipleChoiceField(required=False, label='Looking
> >> For', widget=forms.CheckboxSelectMultiple, choices=LOOKING_FOR, initial=
> >> {"lookingfor": [1,2,3]})
> >

You are specifying the initial values for the form field. So you don't
need to (and should not) pass in a dictionary. You only pass in the
initial values. So something like

        initial = ['Friendship', 'Networking']
        
in the field definition will work (and this time, I actually tested it
to make sure!).

The dictionary is only used when passing initial values into the Form
class, since that initial value data structure has to apply to multiple
fields at once. Thus:

        p_form = ProfileForm(initial={"lookingfor": ['Friendship']})
        
would set the initial value for the lookingfor field (and override any
initial value you specified in the field when you defined the form).

Hopefully that clears up the confusion. For a field, pass in only the
value. For initial values passed to the form constructor, pass in the
dictionary.

Regards,
Malcolm


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