Created
May 14, 2020 19:39
-
-
Save jangia/914782ffaac48498788d631a041b0692 to your computer and use it in GitHub Desktop.
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): | |
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