Skip to content

Instantly share code, notes, and snippets.

@jangia
Created May 14, 2020 19:39
Show Gist options
  • Save jangia/914782ffaac48498788d631a041b0692 to your computer and use it in GitHub Desktop.
Save jangia/914782ffaac48498788d631a041b0692 to your computer and use it in GitHub Desktop.
def search(request):
try:
q = request.GET.get('q')
except:
q = None
if q:
queries = q.split(' ')
items = Item.objects.none()
for query in queries:
items = items | Item.objects.filter(Q(title__icontains=query))
context = {'query': q, 'items': items}
template = 'results-page.html'
else:
template = "home-page.html"
context = {}
return render(request, template, context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment