Posts

Showing posts with the label Python Queries.

Querying Django dependent dropdowns

Image
How to Implement Dependent/Chained Dropdown List with Django Dependent or chained dropdown list is a special field that relies on a previously selected field so to display a list of filtered options. A common use case is on the selection of state/province and cities, where you first pick the state, and then based on the state, the application displays a list of cities located in the state. Example Scenario Take the application below as an example: models.py from django.db import models class Country ( models . Model ): name = models . CharField ( max_length = 30 ) def __str__ ( self ): return self . name class City ( models . Model ): country = models . ForeignKey ( Country , on_delete = models . CASCADE ) name = models . CharField ( max_length = 30 ) def __str__ ( self ): return self . name class Person ( models . Model ): name = models . CharField ( max_length = 100 ) birthdate = models ....