def ajax_search request query request POST get queryString if query qs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def ajax_search(request):
query = request.POST.get('queryString')
if query:
qset_album = ( Q(album__icontains=query) )
albums = Twit.objects.filter(qset_album).distinct()[:5]
qset_artist = ( Q(artist__icontains=query) )
artists = Twit.objects.filter(qset_artist).distinct()[:5]
qset_track = ( Q(name__icontains=query) )
tracks = Track.objects.filter(qset_track).distinct()[:5]
return render_to_response('ajax_search.html',{"albums": albums, "artists": artists, "tracks": tracks})