I have the django 1.11 code as below and we are using django-filter==1.0 library for filters.
and below is the code according to django 1.11
Models:
class BaseItem(models.Model):
CHOICES = (
(STATUS_ACTIVE, 'Active'),
(STATUS_INACTIVE, 'Inactive'),
)
class Item(BaseItem):
name = models.CharField(null=True)
symbol = models.CharField(null=False)
Filter
class ItemFilterSet(django_filters.FilterSet):
status = django_filters.MultipleChoiceFilter(choices=Item.CHOICES, widget=CSVWidget)
class Meta:
model = Item
fields = ['symbol']
strict = STRICTNESS.RAISE_VALIDATION_ERROR
Viewset
class ItemViewSet(ModelViewSet):
http_method_names = ['get', 'post']
serializer_class = ItemSerializer
queryset = Item.objects.all()
filterset_class = ItemFilterSet
def filter_queryset(self, queryset):
try:
return super().filter_queryset(queryset)
except ValidationError as e:
if 'symbol' in e.error_dict:
raise exceptions.ValidationError(detail=e.message_dict)
raise e
But in Django 2.2 version we have used django-filter==2.0 library, but in this library, this strictness has been moved to view as per below link.
django-filter other github link
https://github.com/stephenfin/django-filter/commit/552c35ac45b965c2d68e97f9cfdeef940f17d6ea
So my question is, according to django-filter 2.0 and django 2.2 , in the view, how to handle strictness behaviour in django 2.2 ?