How to create dependent dropdown in Django | Chained Dropdown

Moeed Rafique
2 min readApr 5, 2021

After you setup your project in Django and everything is good and running then follow the next steps. Note (this method can also work to create dependent dropdown in Modelforms.

For Better Understanding visit at https://www.sabab.tech .

First of all you have to install a library using pip.

$ pip install django-smart-selects

After you have installed the library then add it to the installed apps in your setting.py file.

Once you have added it to the installed apps now the next step is to add the smart selects url in your urls.py file.(Note the urls.py file is of your main project)

Awesome! you have now finished the basic setup of smart_select now its time to create the actual chained dropdown.

First of all we will create the models. So open your models.py file.

So in your models.py file add the following code. This is the detailed code to help you understand what is happening in the projects. Below this code there is short piece of code explaining what the smart_select is doing.

Checking it in Admin Panel = >

Display on Client Side = >
In order to display the dropdown in client side I have used model form. You have to create a modelform in Django. Add a new forms.py file add check this picture for more info.

Originally published at https://www.sabab.tech on April 5, 2021.

--

--