Created
July 23, 2012 18:58
-
-
Save douglasmiranda/3165425 to your computer and use it in GitHub Desktop.
Django: construct search with prefixes - code from djang.contrib.admin.views.main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Apply keyword searches. | |
def construct_search(field_name): | |
if field_name.startswith('^'): | |
return "%s__istartswith" % field_name[1:] | |
elif field_name.startswith('='): | |
return "%s__iexact" % field_name[1:] | |
elif field_name.startswith('@'): | |
return "%s__search" % field_name[1:] | |
else: | |
return "%s__icontains" % field_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment