mardi 2 juillet 2019

How do I use a Checkbox in DjangoFilter to switch between filtering on value = True and value = *

I want to filter a table (django-tables2), using a checkbox, to show only entries marked "new" or all entries (i.e. not filter the table).

In my FilterSet I defined a BooleanFilter (tried a ChoiceFilter as well) with a CheckboxInput widget.

class MyFitlerSet(django_filter.FilterSet):
    is_new = django_filters.BooleanFilter(label='Aktuell', widget=forms.CheckboxInput)

How do I map False (or whatever the checkbox returns to any? Currently, I can either show the "new" or the "old" values. But I'd rather show only "New" and "New" and "Old" values.




Aucun commentaire:

Enregistrer un commentaire