From 9a81c6e2549f81c7c5f003646d6ca9a7953fa0d8 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 20 Mar 2012 15:51:38 +0530 Subject: [PATCH] fix error in /stops/ api call --- chaloBEST/mumbai/apiviews.py | 4 ++-- chaloBEST/mumbai/models.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/chaloBEST/mumbai/apiviews.py b/chaloBEST/mumbai/apiviews.py index dbafba8..c7935d4 100644 --- a/chaloBEST/mumbai/apiviews.py +++ b/chaloBEST/mumbai/apiviews.py @@ -67,9 +67,9 @@ def areas(request): def stops(request): q = request.GET.get("q", "") if q != '': - qset = Stop.objects.find_approximate(q, TRIGRAM_THRESHOLD) + qset = Stop.objects.find_approximate(q, TRIGRAM_THRESHOLD).select_related() else: - qset = Stop.objects.all() + qset = Stop.objects.all().select_related() srid = int(request.GET.get("srid", 4326)) return render_to_json_response({ 'type': 'FeatureCollection', diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index a59d92e..9c1a2c6 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -144,6 +144,10 @@ class Stop(models.Model): alt_names = generic.GenericRelation("AlternativeName") def get_dict(self): + routes = [] + for r in self.routedetail_set.all(): + if r.route is not None: + routes.append(r.route) return { 'id': self.id, 'code': self.code, @@ -154,7 +158,7 @@ class Stop(models.Model): 'area': self.area.name, 'name_mr': self.name_mr, 'direction': self.dbdirection, - 'routes': ", ".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]), + 'routes': ", ".join([r.alias for r in routes]), 'alternative_names': ", ".join([a.name for a in self.alt_names.all().filter(typ='common')]) }