dependent-dropdown-example
dependent-dropdown-example copied to clipboard
Update person_form.html
if user do not select country, updates cities without send request to server. Otherwise server raises internal error.
HI its actually awesome, need more help.
My form is like below: Continent Country State City
Can you please help me on that with form code?
class Continent(models.Model): name = models.CharField(max_length=30)
def __str__(self):
return self.name
class Country(models.Model): name = models.CharField(max_length=30) continent = models.ForeignKey(Continent, on_delete=models.CASCADE)
def __str__(self):
return self.name
class State(models.Model): name = models.CharField(max_length=40) country = models.ForeignKey(Country, on_delete=models.CASCADE)
def __init__(self):
return self.name
class City(models.Model): country = models.ForeignKey(State, 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.DateField(null=True, blank=True) country = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True) state = models.ForeignKey(State, on_delete=models.SET_NULL, null=True) city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)
def __str__(self):
return self.name