Hello,

I have a model that is used by a few different model forms.

Model
class QuestionAnswer(models.Model):
    ...
    qanswer_answer = models.CharField(max_length=1, null=False, 
default=None, blank=False)

Now I have modelform that I use to collect info from the user. User selects 
all that apply and I want to save only the count of selected checkboxes and 
save it to the QuestionAnswer model. 

Form
class MultiAnswerForm(forms.ModelForm):
    qanswer_answer = forms.MultipleChoiceField(choices=MULTIANSWER, 
required=True, widget=forms.CheckboxSelectMultiple)
    class Meta:
        model = QuestionAnswer
        fields = '__all__'

In the view I check that fields are valid and I guess that's where I have 
to save the count instead of actual choices?

View
instance = multi_answer_form.save(commit=False)
                    instance.qanswer_answer = 
multi_answer_form.cleaned_data.get('qanswer_answer')
                    instance.save()

How do I get the count of selected checkboxes? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0f557f72-0d69-43b9-b7a6-9fec31f4c636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to