这是使用的解决方案
limit_choices_to
class Project(models.Model):
project_name = models.CharField(max_length=100)
province = models.ForeignKey(Province, limit_choices_to={“country”: 1})
</code>
我在Django中有以下模型,并使用
聪明
</跨度>
-selects:
class Country(models.Model):
name = models.CharField(max_length = 100)
class省(models.Model):
name =models.CharField (max_length = 100)
country = models.ForeignKey(国家)
类
市
</跨度>
(models.Model):
name = models.CharField(max_length = 100)
country = models.ForeignKey(国家)
省= models.ForeignKey