From 2a1850bb12ebfc40ca8ee7607eb3b64ed7c76ff9 Mon Sep 17 00:00:00 2001 From: Ruzal Date: Sat, 18 Nov 2023 21:05:04 +0300 Subject: [PATCH] Fixed ProjectFilter --- backend/api/filters.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/api/filters.py b/backend/api/filters.py index a5e39aa..7aeddf4 100644 --- a/backend/api/filters.py +++ b/backend/api/filters.py @@ -1,5 +1,6 @@ import django_filters from django.db.models import Q +from django.http import Http404 from django.utils import timezone from django_filters.rest_framework import FilterSet, filters from taggit.models import Tag @@ -82,6 +83,15 @@ class ProjectFilter(FilterSet): field_name='end_datetime', lookup_expr='lte' ) + def filter_queryset(self, queryset): + for name, value in self.data.items(): + try: + queryset = super().filter_queryset(queryset) + except (ValueError, self.Meta.model.DoesNotExist): + raise Http404("Invalid filter value for {}".format(name)) + + return queryset + class Meta: model = Project fields = [