From 154701bea588113ba53d29d5934d5a2048c8a5ba Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 16 Jan 2015 08:56:36 -0500 Subject: [PATCH] show most common keywords first --- core/lookups.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/lookups.py b/core/lookups.py index 3c23cce8..f49060e5 100644 --- a/core/lookups.py +++ b/core/lookups.py @@ -2,6 +2,7 @@ from selectable.base import ModelLookup from selectable.registry import registry from django.contrib.auth.models import User +from django.db.models import Count from regluit.core.models import Work, PublisherName, Edition, Subject class OwnerLookup(ModelLookup): @@ -46,6 +47,9 @@ class EditionLookup(ModelLookup): class SubjectLookup(ModelLookup): model = Subject search_fields = ('name__icontains',) + + def get_query(self, request, term): + return super(SubjectLookup, self).get_query( request, term).annotate(Count('works')).order_by('-works__count') registry.register(OwnerLookup) registry.register(WorkLookup)