feature type ajax-select (with custom lookup class)
This commit is contained in:
parent
86b2e2f597
commit
9232052135
22
gazetteer/places/lookups.py
Normal file
22
gazetteer/places/lookups.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from places.models import FeatureType
|
||||
from django.db.models import Q
|
||||
|
||||
class FeatureTypeLookup(object):
|
||||
|
||||
def get_query(self,q,request):
|
||||
""" return a query set. you also have access to request.user if needed """
|
||||
return Contact.objects.filter(Q(code__icontains=q) | Q(name__icontains=q))
|
||||
|
||||
def format_result(self,ftype):
|
||||
""" the search results display in the dropdown menu. may contain html and multiple-lines. will remove any | """
|
||||
return u"%s: %s" % (ftype.code, ftype.name,)
|
||||
|
||||
def format_item(self,contact):
|
||||
""" the display of a currently selected object in the area below the search box. html is OK """
|
||||
return unicode(contact)
|
||||
|
||||
def get_objects(self,ids):
|
||||
""" given a list of ids, return the objects ordered as you would like them on the admin page.
|
||||
this is for displaying the currently selected items (in the case of a ManyToMany field)
|
||||
"""
|
||||
return FeatureType.objects.filter(pk__in=ids).order_by('code')
|
|
@ -88,6 +88,7 @@ AJAX_LOOKUP_CHANNELS = {
|
|||
# the simplest case, pass a DICT with the model and field to search against :
|
||||
'authority_record' : dict(model='places.authorityrecord', search_field='preferred_name'),
|
||||
'time_frame': dict(model='places.timeframe', search_field='description'),
|
||||
'feature_type': ('places.lookups', 'FeatureTypeLookup'),
|
||||
# this generates a simple channel
|
||||
# specifying the model Track in the music app, and searching against the 'title' field
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user