From 1bf94b7053ba29d05feae412f3a8f9a15de44a84 Mon Sep 17 00:00:00 2001 From: Jacob Hilker Date: Tue, 11 Feb 2014 17:28:57 -0500 Subject: [PATCH] add sorting by length of School.name --- karmaworld/apps/courses/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 7ef80eb..42900f5 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -113,7 +113,7 @@ def school_list(request): # get the schools as a id name dict, _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]) + matching_school_names = sorted(list(School.objects.filter(name__icontains=_query)[:20]),key=lambda o:len(o.name)) _schools = matching_school_aliases[:2] + matching_school_names schools = [{'id': s.id, 'name': s.name} for s in _schools] -- 2.25.1