I have a contact/address app that allows users to search the database for contact entries. The current view will return an object (Entry()) and display its fields. The code is as follows:
def search_page(request):
form = SearchForm()
entrylinks = []
show_results = True
if request.GET.has_key('query'):
show_results = True
query = request.GET['query'].strip()
if query:
form = SearchForm({'query' : query})
entrylinks = \
Entry.objects.filter (name__icontains=query)[:10]
variables = RequestContext(request, { 'form': form,
'entrylinks': entrylinks,
'show_results': show_results
})
return render_to_response('search.html', variables)
I'd like to add an "if" statement to the view that would recognize when there are multiple objects returned (people with the same name in the database) and in such a case, divert the returned objects to a different template (which would simply list the returned objects so the user could choose which he/she'd prefer). Can anyone show what such a statement would look like? Thanks.