from-to search route

This commit is contained in:
2025-05-26 17:36:30 +03:00
parent c761c60818
commit 46945e32a8
8 changed files with 207 additions and 25 deletions

View File

@@ -12,6 +12,9 @@ class SearchRouteListView(generics.ListAPIView):
def get_queryset(self):
owner_type = self.kwargs.get('owner_type')
from_city = self.request.query_params.get('from')
to_city = self.request.query_params.get('to')
valid_types = [choice[0] for choice in owner_type_choices]
current_time = timezone.now()
@@ -23,6 +26,12 @@ class SearchRouteListView(generics.ListAPIView):
owner_type=owner_type,
status="actual")
# фильтруем по городам если они указаны
if from_city:
queryset = queryset.filter(from_city__name__iexact=from_city)
if to_city:
queryset = queryset.filter(to_city__name__iexact=to_city)
# фильтруем по времени в зависимости от типа
if owner_type == 'mover':
queryset = queryset.filter(departure_DT__gt=current_time)