i have two select box one is country
and another is state
. both value can be access to the database. I have select country select box then automatically another select box value change related to that country select box.
Example: I have select country india then automatically fetch the value states of another select box. I am using ajax get the value.
def constituency1(request):
country= Loksabha.objects.values('country_name').distinct('country_name')
terms = Loksabha.objects.values('lok_sabha').distinct('lok_sabha')
states=Loksabha.objects.values('state_name').distinct('state_name')
if 'p1' in request.GET and request.GET['p1']:
p1 = request.GET['p1']
states=Loksabha.objects.values('state_name').distinct('state_name').filter(country_name='p1')
if 'p2' in request.GET and request.GET['p2']:
p2 = request.GET['p2']
state_filter = Loksabha.objects.filter(state_name=p1,constituency_name=p2)