Hello everyone,
I am using django filter on a DRF viewset to filter on a foreign key. This works as expected except when I want to filter entries where the foreign key is null.
I tried creating FilterSet to overcome that limitation:
class ReservationServiceFilter(django_filters.FilterSet):
service = django_filters.ModelChoiceFilter(queryset=models.Service.objects.values_list('id', 'name'), null_value='null', null_label='Custom')
class Meta:
model = models.ReservationService
fields = ['date', 'service']
But unlike
ChoiceFilter,
ModelChoiceFilter does not allow
null_value and
null_label arguments. Looking at the code, it seems only ChoiceFilter accepts it (not even MultipleChoiceFilter).
I was wondering if in fact all filters should accept
null_value and
null_label arguments as null may be a valid value for most types ? or should it only be implemented for ModelChoiceFilter ? or no other ?
Michael