I am new to django and jquery. I am working on a django-based app where I have 3 drop downs in a form. 1. Campus 2. School 3. Centre
The hierarchy is Campuses have schools and schools have centres. I want to interlink these drop-downs.
For example, I have got 3 campuses, say Campus1, Campus2, Campus3. If I select Campus1, I should only get to select schools in campus1 and continuing this, if I select School1 then I need to be able to select centres of School1 and all other options should get hidden.
I searched on net and have tried this http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/ but it doesn't seem to work for me. I have also checked this http://www.javascriptkit.com/script/script2/triplecombo.shtml but since I am using ModelForm to create forms, this doesn't fit to my needs.
Please guide me to do this.
Thanks
You might need to use the following technologies:
Let's have a look at an example(Not really tested this, just from the top of my mind):
Models.py
Forms.py
Now, write a method in your views that returns a json object for schools under a campus and centres under a school:
Views.py
Now write a ajax/jquery method to fetch the data and populate the
select
elements in the HTML.AJAX/jQuery
Rather than re-inventing the wheel, I would use Django Smart Selects or Django Autocomplete Light
I haven't tried either yet but I'm about to use one or both of them in an upcoming project.