diff --git a/backend/right_tree/api/filters.py b/backend/right_tree/api/filters.py index 21d291d..28ad173 100644 --- a/backend/right_tree/api/filters.py +++ b/backend/right_tree/api/filters.py @@ -6,6 +6,7 @@ from django.db.models import Q from .models import EcologicalRegion, EcologicalDistrictLayer, SoilOrder, SoilVariant from .utils import get_point_from_coordinates + def coordinate_filter(request, queryset): coordinates = request.query_params.get('coordinates') @@ -35,6 +36,12 @@ def soil_variant_filter(request, queryset): return queryset +def zone_filter(request, queryset): + zone = request.query_params.get('zone') + zone_json = json.loads(zone) + return queryset.filter(zones__id__contains=zone_json['id']).distinct() + + def soil_order_coordinate_filter(coordinates): pnt = get_point_from_coordinates(coordinates) try: @@ -48,4 +55,5 @@ def ecological_district_coordinate_filter(coordinates): try: return EcologicalDistrictLayer.objects.filter(geom__intersects=pnt) except EcologicalDistrictLayer.DoesNotExist: - raise Http404(f"Ecological district layer cannot be found for point {pnt}") + raise Http404( + f"Ecological district layer cannot be found for point {pnt}") diff --git a/backend/right_tree/api/views.py b/backend/right_tree/api/views.py index 8cad196..c318f39 100644 --- a/backend/right_tree/api/views.py +++ b/backend/right_tree/api/views.py @@ -29,6 +29,7 @@ class PlantViewSet(viewsets.ModelViewSet): queryset = Plant.objects.all() queryset = coordinate_filter(self.request, queryset) queryset = soil_variant_filter(self.request, queryset) + queryset = zone_filter(self.request, queryset) return queryset