2011-08-30 19:32:30 +00:00
|
|
|
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 """
|
2011-08-30 19:48:20 +00:00
|
|
|
return FeatureType.objects.filter(Q(code__icontains=q) | Q(name__icontains=q))
|
2011-08-30 19:32:30 +00:00
|
|
|
|
|
|
|
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,)
|
|
|
|
|
2011-08-30 19:48:20 +00:00
|
|
|
def format_item(self,ftype):
|
2011-08-30 19:32:30 +00:00
|
|
|
""" the display of a currently selected object in the area below the search box. html is OK """
|
2011-08-30 19:48:20 +00:00
|
|
|
return unicode(ftype)
|
2011-08-30 19:32:30 +00:00
|
|
|
|
|
|
|
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')
|