Django Filter BooleanFilter с 3 опциями - True, False и Both

I am trying to create a filter for where an attribute is null with Django-Filter for an Appointment model. The relevant docs are: https://django-filter.readthedocs.io/en/stable/guide/tips.html?highlight=isnull#solution-1-using-a-booleanfilter-with-isnull

class Appointment(models.Model):
    ...
    professional = models.ForeignKey(telemed_models.HealthcareProfessionalProfile, null=True, blank=True, on_delete=models.SET_NULL, related_name='appointments', verbose_name=_('professional'))
    ... 

Фильтр, который мне нужен, называется 'Unassigned', он будет отфильтровывать те встречи, для которых не назначен специалист.

Я использую флажок для этого:

class AppointmentListFilter(django_filters.FilterSet):
    ...
    unassigned = django_filters.BooleanFilter(field_name='professional', lookup_expr='isnull', label=_("Unassigned"), widget=forms.widgets.CheckboxInput())
    ...

При загрузке страницы (т. е. до нажатия кнопки "Фильтровать элементы") все элементы отображаются (очевидно), а флажок снят.

Странное поведение является результатом следующего: После нажатия кнопки "Фильтровать элементы" флажок технически "работает", когда он используется - т.е. снятый флажок показывает встречи, где профессионал не равен null. Установленный флажок показывает встречи, где профессионал равен null.

So, there's a clash with the fresh/page load state. Basically that on pageload unchecked means "all items", but after filtering, unchecked means "only those with a value". While the filter is technically doing what it is supposed to do, this is bad UX because it's quite confusing for the user.

Кто-нибудь знает хороший способ решения этой проблемы? Я имею в виду, что булево кажется правильным способом сделать это (как предлагает документация), но вам вроде как нужно 3 состояния (not_null, null и оба), а не только 2.

Вернуться на верх