Created
June 17, 2011 12:18
-
-
Save hughsaunders/1031309 to your computer and use it in GitHub Desktop.
Search View using Julien Phalip's technique.
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
def search(request): | |
search_string=request.POST['search_string'] | |
if re.match(r'^\s*$',search_string): return redirect('home') | |
results=[] | |
search_fields=('id','name') | |
equipment_models = \ | |
[model for model in django.db.models.get_models() if\ | |
model._meta.db_table.startswith("equipment_")] | |
for model in equipment_models: | |
query=halipsearch.get_query(search_string,search_fields) | |
results+=(model.objects.filter(query)) | |
extra_context={'object_list':results, | |
'pagetitle':"Search Results for '"+search_string+"'"} | |
return render_to_response( | |
'equipment/generic_list.html', | |
extra_context, | |
context_instance=RequestContext(request) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, will this solve my problem of getting related results instead of all the objects?
http://stackoverflow.com/questions/26635406/django-query-in-detailview