1👍
✅
The field forms.ModelMultipleChoiceField
needs a model for the choices.
If you want to assign strings, you can use forms.MultipleChoiceField
instead.
sname = forms.MultipleChoiceField(
# list of tuples; the first of each pair is the value to be
# returned when selected, the second is the value to be displayed
choices=[
(e, e)
e for e in CustomStudent.objects.all().values_list('sname', flat=True)],
required=False,
widget=forms.CheckboxSelectMultiple(
attrs={'class':' form-check-input' ' form-check-inline'}))
See detailed description of the attribute choices
.
👤Ralf
Source:stackexchange.com