Sharpless512
Sharpless512

Reputation: 3222

MultipleChoiceFilter to Checkboxes

I have a ModelMultipleChoiceFilter working, however I cant find a way to adjust it from a input multiple choice to a checkbox list.

This is what I currently have:

What I currently have

This is what I want to convert it to:

enter image description here

My current code:

class GameFilter(django_filters.FilterSet):

gamemodes = django_filters.ModelMultipleChoiceFilter(
        queryset=GameMode.objects.all(),
        label='Game modes (or)',
    )

Upvotes: 2

Views: 965

Answers (1)

Abdul Aziz Barkat
Abdul Aziz Barkat

Reputation: 21787

Simply pass the keyword argument widget with CheckboxSelectMultiple [Django docs] to your filter:

from django import forms

class GameFilter(django_filters.FilterSet):
    gamemodes = django_filters.ModelMultipleChoiceFilter(
        queryset=GameMode.objects.all(),
        label='Game modes (or)',
        widget=forms.CheckboxSelectMultiple,
    )

Upvotes: 4

Related Questions