I call a form by ajax. In this form, this is a part with a checkbox list. The django widget forms.ModelMultipleChoiceField(queryset= ..., widget=forms.CheckboxSelectMultiple, required=False) not displayed
class AnswerForm(forms.ModelForm):
skills = forms.ModelMultipleChoiceField(queryset= Skill.objects.filter(subject_id = 1), widget=forms.CheckboxSelectMultiple, required=False)
waitings = forms.ModelMultipleChoiceField(queryset= Waiting.objects.filter(theme__subject_id = 1).order_by("theme"), widget=forms.CheckboxSelectMultiple, required=False)
knowledges = forms.ModelMultipleChoiceField(queryset= Knowledge.objects.filter(theme__subject_id = 1 ).order_by("-level").order_by("theme"), widget=forms.CheckboxSelectMultiple, required=False)
class Meta:
model = Answer
fields = '__all__'
def ajax_create_answer(request):
id_model = int(request.POST.get('id_model'))
data = {}
form_ans = inlineformset_factory( Item , Answer , fields=('content','right', 'skills','waitings','knowledges',) , extra= 4 )
print(form_ans)
template = 'learning/show_vf_multiples.html'
html = render_to_string(template, context )
data['html'] = html
return JsonResponse(data)
I want the checkbox lists on my form not the default select. Thanks.
Aucun commentaire:
Enregistrer un commentaire