0

Django model form with m2m field only showing one select box even im using FilteredSelectMultiple as the widget for that field . required admin filesbase files are added

class ExamForm(forms.ModelForm):

question_m2m = forms.ModelMultipleChoiceField(queryset=Question.objects.all(),
                                         label=('Select Question'),
                                         widget=FilteredSelectMultiple(
                                             ('question'),
                                             False,
                                         ))
class Meta:
    model=Exam
    fields = ('question_m2m',)

and static files are aded in base template

 <link href="{% static 'css/theme.css' %}" rel="stylesheet" media="all">
<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/jquery.init.js' %}"></script>
{{ examform.media }}
{{form.media}}

here is what Im getting

shijin
  • 461
  • 4
  • 11

1 Answers1

0

I think you are looking for filter_horizontal for the django admin. If that is the case, you should add the forms to an admin:

class ExamFormAdmin(admin.ModelAdmin):
    form = ExamForm
    ...

If you would like to use filter_horizontal outside of the admin interface, you have to include the corresponding static files yourself, which is described in this question.

dsax7
  • 1,333
  • 22
  • 36