Ticket #2559: django-search_fields-operators_pre_magic_removal.diff
File django-search_fields-operators_pre_magic_removal.diff, 1.4 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/views/main.py
218 218 lookup_params['select_related'] = True 219 219 break 220 220 lookup_params['order_by'] = ((order_type == 'desc' and '-' or '') + lookup_order_field,) 221 222 # Apply keyword searches. 223 def construct_search(field_name): 224 if field_name.startswith('^'): 225 return "%s__istartswith" % field_name[1:] 226 elif field_name.startswith('='): 227 return "%s__iexact" % field_name[1:] 228 elif field_name.startswith('@'): 229 return "%s__search" % field_name[1:] 230 else: 231 return "%s__icontains" % field_name 232 221 233 if lookup_opts.admin.search_fields and query: 222 234 complex_queries = [] 223 235 for bit in query.split(): 224 236 or_queries = [] 225 237 for field_name in lookup_opts.admin.search_fields: 226 or_queries.append(meta.Q(**{ '%s__icontains' % field_name: bit}))238 or_queries.append(meta.Q(**{construct_search(field_name): bit})) 227 239 complex_queries.append(reduce(operator.or_, or_queries)) 228 240 lookup_params['complex'] = reduce(operator.and_, complex_queries) 229 241 if opts.one_to_one_field: