From f745a47cdb914dab2fc73bc6d0d465db06950c37 Mon Sep 17 00:00:00 2001 From: Timofey Date: Fri, 23 May 2025 15:49:00 +0300 Subject: [PATCH] fix / dont dispay not actual items --- backend/api/main/serializers.py | 2 -- backend/api/search/serializers.py | 2 -- backend/api/search/views.py | 16 +++++++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/backend/api/main/serializers.py b/backend/api/main/serializers.py index 9d8b852..798fd60 100644 --- a/backend/api/main/serializers.py +++ b/backend/api/main/serializers.py @@ -103,14 +103,12 @@ class HomePageRouteSerializer(RouteSerializer): def get_country_from(self, obj): return self.get_from_country_name(obj) - def get_end_point(self, obj): return self.get_to_city_name(obj) def get_country_to(self, obj): return self.get_to_country_name(obj) - def get_cargo_type(self, obj): return self.get_formatted_cargo_type(obj) diff --git a/backend/api/search/serializers.py b/backend/api/search/serializers.py index 87f3ade..bfa408f 100644 --- a/backend/api/search/serializers.py +++ b/backend/api/search/serializers.py @@ -6,5 +6,3 @@ class SearchRouteSerializer(HomePageRouteSerializer): class Meta(HomePageRouteSerializer.Meta): model = Route fields = HomePageRouteSerializer.Meta.fields - - diff --git a/backend/api/search/views.py b/backend/api/search/views.py index a705a78..e8416ef 100644 --- a/backend/api/search/views.py +++ b/backend/api/search/views.py @@ -4,7 +4,7 @@ from .serializers import SearchRouteSerializer from api.utils.pagination import StandardResultsSetPagination from rest_framework.exceptions import ValidationError from routes.constants.routeChoices import owner_type_choices - +from django.utils import timezone class SearchRouteListView(generics.ListAPIView): serializer_class = SearchRouteSerializer @@ -13,12 +13,18 @@ class SearchRouteListView(generics.ListAPIView): def get_queryset(self): owner_type = self.kwargs.get('owner_type') valid_types = [choice[0] for choice in owner_type_choices] + current_time = timezone.now() if not owner_type or owner_type not in valid_types: raise ValidationError("Invalid or missing owner_type. Must be either 'customer' or 'mover'") - queryset = Route.objects.filter( - owner_type=owner_type - ).order_by('-arrival_DT') + # базовый фильтр по типу владельца + queryset = Route.objects.filter(owner_type=owner_type) - return queryset + # фильтруем по времени в зависимости от типа + if owner_type == 'mover': + queryset = queryset.filter(departure_DT__gt=current_time) + else: # customer + queryset = queryset.filter(arrival_DT__gt=current_time) + + return queryset.order_by('-arrival_DT')