add sorting by length of School.name 330/head
authorJacob Hilker <hilker.j@gmail.com>
Tue, 11 Feb 2014 22:28:57 +0000 (17:28 -0500)
committerJacob Hilker <hilker.j@gmail.com>
Tue, 11 Feb 2014 22:28:57 +0000 (17:28 -0500)
karmaworld/apps/courses/views.py

index 7ef80ebf7e1685f774a5d17aedcd0d1197741eb7..42900f5ed9304a6e53f219cf6ced80e326705ccc 100644 (file)
@@ -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]