From 7357dd53e48eb975a32c5fecc01ba01e75b417c5 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 3 Aug 2017 18:35:23 +0200 Subject: Lookups: add operations --- archaeological_operations/lookups.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 archaeological_operations/lookups.py (limited to 'archaeological_operations') 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"%s" % item.cached_label -- cgit v1.2.3