I have a search form and it works fine. Now I would like my search form autocomplete.I tried using django autocomplete light but I have a problem implementing it.
Is it possible to use my existing code, add JavaScript and make it work? I tried to do it myself but I came to a wall.
I would really appreciate if someone could help me with this, give me a hint or a link for a working demo or tutorial.
This is my current code. Thanks for your time.
views.py
def search(request):
if 'q' in request.GET and request.GET['q']:
q = request.GET['q']
search_list = Book.objects.filter(
Q(title__icontains=q) | Q(description__icontains=q))
return render_to_response('books/search_results.html', {'search_list': search_list, 'query': q}, context_instance=RequestContext(request))
else:
return render_to_response('books/please_submit.html', {}, context_instance=RequestContext(request))
urls.py
urlpatterns = patterns('',
url(r'^search/$','papers.views.search', name='search'),
)
search.html
<form method='get' action='/search/'>
<input type='text' name='q' class="btn btn-theme btn-sm btn-min-block biggerForm">
<input type='submit' value='Search' class="btn btn-theme btn-sm btn-min-block">
</form>