summaryrefslogtreecommitdiff
path: root/archaeological_operations/lookups.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-03 18:35:23 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-08-03 18:35:23 +0200
commit5152dec20d1ad67fc3cd8d0013b2f3b0bb46a271 (patch)
treefb818c98a0786ad6dc1cf3efe2bdbb66f5d93414 /archaeological_operations/lookups.py
parent61ea7576eda6a62f1eba30f99fa2069de57297e1 (diff)
downloadIshtar-5152dec20d1ad67fc3cd8d0013b2f3b0bb46a271.tar.bz2
Ishtar-5152dec20d1ad67fc3cd8d0013b2f3b0bb46a271.zip
Lookups: add operations
Diffstat (limited to 'archaeological_operations/lookups.py')
-rw-r--r--archaeological_operations/lookups.py21
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