how to set initial value for select multiple

4,402 views
Skip to first unread message

cschand

unread,
Feb 14, 2008, 12:34:00 AM2/14/08
to Django users

I have a form

class NetworkForm(forms.Form):
choices = []
for network in Network.objects.all():
choices.append((network.id, network.name))

network =
forms.CharField(widget=forms.CheckboxSelectMultiple(choices=choices))

and in view i called this network form by
network_form = NetworkForm()

My problem is i want to set initial value for the given network
CheckboxSelectMultiple field..

Is there is any way to go it?

Thanks in advance

cschand

Matt McClanahan

unread,
Feb 14, 2008, 3:52:37 AM2/14/08
to Django users
On Feb 13, 9:34 pm, cschand <csch...@gmail.com> wrote:

> My problem is i want to set initial value for the given network
> CheckboxSelectMultiple field..

Since it's a multiple value field, it expects a list of initial
values.

NetworkForm(initial={'network': [1,2,3]})

Matt
Reply all
Reply to author
Forward
0 new messages