how to dispaly data in dropdown when i click on first dropdown item ,means related or filtered data suppose i click on city dropdown all the city related devices from same table will be displayed for perticular city in python django
What I have tried:
-----views.py---------
def show3(request):
employees = Employee.objects.all().values('city').distinct()
if 'nameEmployees' in request.GET:
nameEmployees = 'nameEmployees' in request.POST and request.POST['nameEmployees']
employees = Employee.objects.filter(Q(city__contains='nameEmployees'))
return render(request, 'testapp/show3.html', {'employees':employees })
---------------show3.html------------
<form class="form" method="POST" action="show3">
<select id="nameEmployees" name="nameEmployees" class="form-control" onchange="get_host_name(this.value)">
<option value="%">---------</option>
{% for employee in employees %}
<option value="{{ employee.id }}">{{ employee.city }}</option>
{% endfor %}<br>
</select>
</form>
-
HostName
Search
Back
{% for employee in employees %}
{{ employee.host_name }}
{% endfor %}