show most common keywords first
parent
073040d7ca
commit
154701bea5
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue