Posts

Showing posts with the label multiplechoicefield

Django MultipleChoiceField not showing saved choices

Django MultipleChoiceField not showing saved choices This is what my form looks like. class DecisionMadeForm(forms.ModelForm): option = forms.MultipleChoiceField(required=False, label = "Which option(s) did you choose? (Please check ALL that apply)") class Meta: model = Decision_Made fields = ('option', ) def __init__(self, *args, **kwargs): dec_id = kwargs.pop("dec_id") choicelist = kwargs.pop("choicelist") super(DecisionMadeForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) query = Solution_Options.objects.filter(dec_id = dec_id, archived = 'N').values_list('option', flat=True).distinct() query_choices = [(id, id) for id in query] self.fields['sol_option']=forms.MultipleChoiceField(choices=query_choices, required=False, widget=forms.CheckboxSelectMultiple,label="Which choice did you make?") ...