diff options
Diffstat (limited to 'archaeological_operations/lookups.py')
-rw-r--r-- | archaeological_operations/lookups.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/archaeological_operations/lookups.py b/archaeological_operations/lookups.py new file mode 100644 index 000000000..b6fdaad23 --- /dev/null +++ b/archaeological_operations/lookups.py @@ -0,0 +1,21 @@ +from ajax_select import register, LookupChannel + +from django.db.models import Q +from archaeological_operations.models import Operation + + +@register('operation') +class OperationLookup(LookupChannel): + model = Operation + + def get_query(self, q, request): + query = Q() + for term in q.strip().split(' '): + subquery = ( + Q(cached_label__icontains=term) + ) + query &= subquery + return self.model.objects.filter(query).order_by('cached_label')[:20] + + def format_item_display(self, item): + return u"<span class='ajax-label'>%s</span>" % item.cached_label |