From 40b2cac714e3675614678c94c5fd9a214f1eb596 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Wed, 26 Jun 2013 12:58:25 -0400 Subject: [PATCH] modify the autocomplete ajax method to return School.alias matches before name matches --- karmaworld/apps/courses/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index cc6fe00..ebad7b3 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -78,8 +78,12 @@ def school_list(request): and request.POST.has_key('q'): # if an ajax get request with a 'q' name query # get the schools as a id name dict, - schools = [{'id': s.id, 'name': s.name} for s in \ - School.objects.filter(name__icontains=request.POST['q'])[:4]] + _query = request.POST['q'] + matching_school_aliases = list(School.objects.filter(alias__icontains=_query)) + matching_school_names = list(School.objects.filter(name__icontains=_query)[:20]) + _schools = matching_school_aliases[:2] + matching_school_names + schools = [{'id': s.id, 'name': s.name} for s in _schools] + # return as json return HttpResponse(json.dumps({'status':'success', 'schools': schools}), mimetype="application/json") else: -- 2.25.1