diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index 76ca4a4..e99c5e4 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -39,17 +39,22 @@ def get_routes_ajax(request): for route in routes: - if route.type_transport == 'avia': - route.from_airport = Airport.objects.get(id=route.from_address_point) - route.to_airport = Airport.objects.get(id=route.to_address_point) - route.from_city = route.from_airport.city - route.to_city = route.to_airport.city - else: - route.from_city = City.objects.get(id=route.from_address_point) - route.to_city = City.objects.get(id=route.to_address_point) + try: - route.from_country = route.from_city.country - route.to_country = route.from_city.country + if route.type_transport == 'avia': + route.from_airport = Airport.objects.get(id=route.from_address_point) + route.to_airport = Airport.objects.get(id=route.to_address_point) + route.from_city = route.from_airport.city + route.to_city = route.to_airport.city + else: + route.from_city = City.objects.get(id=route.from_address_point) + route.to_city = City.objects.get(id=route.to_address_point) + + route.from_country = route.from_city.country + route.to_country = route.from_city.country + except Exception as e: + msg = f'get route points = {str(e)}' + print(msg) Dict = { 'routes': routes @@ -69,8 +74,7 @@ def get_routes_ajax(request): 'all__': f'ошибка в запросе = {str(e)}' } } - html = render_to_string('blocks/profile/b_new_route.html', errors_Dict, request=request) - return JsonResponse({'html': html}, status=400) + return JsonResponse(errors_Dict, status=400)