Click here to Skip to main content
14,241,673 members
Rate this:
Please Sign up or sign in to vote.
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100