1👍
✅
This may help:
from django_filters import rest_framework as filters
class CharInFilter(filters.BaseInFilter, filters.CharFilter):
pass
class VehicularAccessRecordInformationFilter(filters.FilterSet):
vehicle_type = CharInFilter(field_name='vehicle_type')
...
class Meta:
model = VehicleAccessRecordInformation
fields = ['vehicle_type', <other_fields>]
BaseInFilter
accepts multiple values separated by comma, and CharFilter
defines a type for the values, i.e. you can use NumberFilter
, ChoiceFilter
, etc.
So that ?vehicle_type=Mixer,Lorry
evaluates to
VehicleAccessRecordInformation.objects.filter(vehicle_type__in=['Mixer', 'Lorry']
Source:stackexchange.com