Skip to content

Commit

Permalink
Merge pull request #213 from volunteers-for-city-projects/project
Browse files Browse the repository at this point in the history
Fixed ProjectFilter
  • Loading branch information
MrRuzal authored Nov 18, 2023
2 parents 1ad3e97 + 2a1850b commit 9c4e095
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/api/filters.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 9c4e095

Please sign in to comment.