Hello,
This application returns schoolmates of lawyers.
When a user searches for first name only and there are more than 1 result I leave the query in the form and ask them to enter a last name. But I thought that it would be nicer if the user just clicks to one of the names and search results are returned directly. (at this point the link takes you to search form again.)
In the template the query and the last name that I need are inside the {% for lawyer in lawyers %}
loop as attributes: lawyer.first
and lawyer.last
. I couldn't figure out how to save them to create a query. Can you help me with how to solve this problem?
Note: The template is below but I put the view function in pastebin.com. It's 60 lines long, I wasn't sure if I should be posting it here.
Thank you.
<html>
<head>
<title>Search results</title>
</head>
<body>
<p>You searched for <strong>{{ first|capfirst }} </strong>.</p>
<p>There are {{ lawyers|length }} {{ first|capfirst }} in the database. Please select one.</p>
{% for lawyer in lawyers %}
<ul><li><a href="/search/">{{ lawyer.first }} {{ lawyer.last }} {{ lawyer.firm_name }} {{ lawyer.school}} class of {{ lawyer.year_graduated }}</a></li></ul>
{% endfor %}
<form action="" method="get">
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
</body>
</html>
Edit
Do I need to create a new view function like this?
def new_query(request):
last_name = request.GET.get('lawyers.last')
first_name = request.GET.get('lawyer.first')
....