Set initial value of checkbox dynamically
django, forms
Solution
You can set the initial to be a list. In this case if you set `YourForm(inital={'weight_training_days': [0,1,2]})` it will default to having Monday, Tuesday and Wednesday selected. You can also do it like so `forms.MultipleChoiceField(... inital=[0,1,2] ...)`
Problem
I have a MultipleChoiceField with a CheckboxSelectMutliple widget: ``` weight_training_days = forms.MultipleChoiceField( help_text=u'(Required) 3 days must be selected', widget=forms.CheckboxSelectMultiple(attrs={ 'inline': True, }), choices=( (0, "Mon"), (1, "Tue"), (2, "Wed"), (3, "Thu"), (4, "Fri"), (5, "Sat"), (6, "Sun"), ), ) ``` What I'm trying to is dynamically set 3 of the 7 checkboxes to "True". Ideally I would do this from the view. ``` def change_challenge_settings_page(request): c = Challenge.objects.get(user__exact = request.user,chal_status=1) layout = 'horizontal' form =UpdateChallengeSettingsForm(initial={'goal': c.level_goal }) return render(request, 'portal/portal_change_challenge_settings.html', {'form': form,'layout': layout,'scorecard_page': True,}) ``` I know how to do this with ChoiceFields (in the example above the "goal" is a ChoiceField) but am stuck when it comes to MultipleChoiceFields. I really appreciate any thoughts/feedback.