from-to search route
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user