#NEWLINE# def make_channel( app_model , search_field ) : #NEWLINE# #INDENT# ' used in get_lookup\n        app_model :   app_name.model_name\n        search_field :  the field to search against and to display in search results ' #NEWLINE# from django.db import models #NEWLINE# ( app_label , model_name ) = app_model . split ( '.' ) #NEWLINE# model = models . get_model ( app_label , model_name ) #NEWLINE# class AjaxChannel ( object ) : #NEWLINE# #INDENT# def get_query( self , q , request ) : #NEWLINE# #INDENT# ' return a query set searching for the query string q ' #NEWLINE# kwargs = { #NEWLINE# #INDENT# ( '%s__icontains' % search_field ) : q , #NEWLINE# #UNINDENT# } #NEWLINE# return model . objects . filter ( ** kwargs ) . order_by ( search_field ) #NEWLINE# #UNINDENT# def format_item( self , obj ) : #NEWLINE# #INDENT# ' format item for simple list of currently selected items ' #NEWLINE# return unicode ( obj ) #NEWLINE# #UNINDENT# def format_result( self , obj ) : #NEWLINE# #INDENT# ' format search result for the drop down of search results. may include html ' #NEWLINE# return unicode ( obj ) #NEWLINE# #UNINDENT# def get_objects( self , ids ) : #NEWLINE# #INDENT# ' get the currently selected objects ' #NEWLINE# return model . objects . filter ( pk__in = ids ) . order_by ( search_field ) #NEWLINE# #UNINDENT# #UNINDENT# return AjaxChannel ( )