Click here to Skip to main content
15,886,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 %}
Posted
Updated 12-May-19 23:48pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900