show most common keywords first

pull/1/head
eric 2015-01-16 08:56:36 -05:00
parent 073040d7ca
commit 154701bea5
1 changed files with 4 additions and 0 deletions

View File

@ -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)