我的django应用程序中有三个模型...
class Counties(models.Model):
name = models.CharField(max_length=20)
executive = model.CharField(max_length=40)
class Boroughs(models.Model):
county = models.ForeignKey(Counties, on_delete=models.CASCADE)
name = models.CharField(max_length=20)
official = models.CharField(max_length=20)
class People(models.Model):
firstname = models.CharField(max_length=20)
lastname = models.CharField(max_length=20)
county = models.ForeignKey(Counties, on_delete=models.CASCADE)
borough = models.ForeignKey(Boroughs, on_delete=models.CASCADE)
现在将记录添加到People
模型时,我希望发生以下情况...
从下拉列表中选择county
时,我需要过滤自治市镇下拉菜单,以便只有属于所选县的自治市镇才会显示在下拉菜单中。
我该怎么做?