Changed stops JSON to dict instead of list

This commit is contained in:
Johannes Randerath 2024-06-11 21:39:19 +02:00
parent 092cc348d6
commit 1dd906a87f

View File

@ -34,7 +34,7 @@ def get_timetable(r, trips, stop_sequences):
def index(request): def index(request):
stops = [{name: getattr(s, name) for name in ['stop_id', 'stop_name', 'stop_lat', 'stop_lon']} for s in Stop.objects.all()] stops = {s.stop_id: {name: getattr(s, name) for name in ['stop_name', 'stop_lat', 'stop_lon']} for s in Stop.objects.all()}
route_name = lambda r : r.route_short_name if r.route_short_name else r.route_long_name route_name = lambda r : r.route_short_name if r.route_short_name else r.route_long_name
routes = [{"route_id": r.route_id, "route_type": r.route_type, "route_name": route_name(r), "agency_id": r.agency_id.agency_id} for r in Route.objects.all()] routes = [{"route_id": r.route_id, "route_type": r.route_type, "route_name": route_name(r), "agency_id": r.agency_id.agency_id} for r in Route.objects.all()]
trips = {r["route_id"]: [t for t in Trip.objects.filter(route_id_id=r["route_id"])] for r in routes} trips = {r["route_id"]: [t for t in Trip.objects.filter(route_id_id=r["route_id"])] for r in routes}