fix error in /stops/ api call

This commit is contained in:
Sanj 2012-03-20 15:51:38 +05:30
parent d61cccf204
commit 9a81c6e254
2 changed files with 7 additions and 3 deletions

View File

@ -67,9 +67,9 @@ def areas(request):
def stops(request): def stops(request):
q = request.GET.get("q", "") q = request.GET.get("q", "")
if q != '': if q != '':
qset = Stop.objects.find_approximate(q, TRIGRAM_THRESHOLD) qset = Stop.objects.find_approximate(q, TRIGRAM_THRESHOLD).select_related()
else: else:
qset = Stop.objects.all() qset = Stop.objects.all().select_related()
srid = int(request.GET.get("srid", 4326)) srid = int(request.GET.get("srid", 4326))
return render_to_json_response({ return render_to_json_response({
'type': 'FeatureCollection', 'type': 'FeatureCollection',

View File

@ -144,6 +144,10 @@ class Stop(models.Model):
alt_names = generic.GenericRelation("AlternativeName") alt_names = generic.GenericRelation("AlternativeName")
def get_dict(self): def get_dict(self):
routes = []
for r in self.routedetail_set.all():
if r.route is not None:
routes.append(r.route)
return { return {
'id': self.id, 'id': self.id,
'code': self.code, 'code': self.code,
@ -154,7 +158,7 @@ class Stop(models.Model):
'area': self.area.name, 'area': self.area.name,
'name_mr': self.name_mr, 'name_mr': self.name_mr,
'direction': self.dbdirection, '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')]) 'alternative_names': ", ".join([a.name for a in self.alt_names.all().filter(typ='common')])
} }