Using a ListView to display search results from a user query.
How can I add a redirect if the item they search for has an exact match, to that specific DetailView?
class WikiSearchView(ListView):
template_name = "encyclopedia/wiki_search.html"
model = Entry
paginate_by = 25
context_object_name = "searchResults"
def get_queryset(self):
search = self.request.GET.get('q')
object_list = Entry.objects.filter(Q(title__icontains=search))
return object_list
I tried to add a try/except with Entry.objects.get to look for an exact match and then use a return redirect(xyz), but that didn't work.