From: Jacob Hilker Date: Tue, 11 Feb 2014 22:28:57 +0000 (-0500) Subject: add sorting by length of School.name X-Git-Tag: release-20150131~148^2~14^2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1bf94b7053ba29d05feae412f3a8f9a15de44a84;p=oweals%2Fkarmaworld.git add sorting by length of School.name --- 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]