django smart_selects, second level won't populate

前端 未结 3 440
无人共我
无人共我 2021-01-25 04:21

I can not get the second level (subcategory/E_cat) drop down to populate. First level (Category) seems to be working fine. I think I\'ve tried just about every reasonable combi

3条回答
  •  Happy的楠姐
    2021-01-25 04:42

    html.file

    include the following if you are using forms

    
    
    

    models.py

    class Continent(models.Model):
            name = models.CharField(max_length=255)
            def __str__(self):
                return self.name
    
        class Country(models.Model):
            continent= models.ForeignKey(Continent)
            name = models.CharField(max_length=255)
            def __str__(self):
                return self.name
    
        class City(models.Model):
            continent= models.ForeignKey(Continent)
            country= ChainedForeignKey(Country, chained_field="continent",  chained_model_field="continent", show_all=False, auto_choose=True, sort=True)
            name = models.CharField(max_length=255)
            def __str__(self):
                return self.name
    
        class Neighborhood(models.Model):
            continent= models.ForeignKey(Continent)
            country= ChainedForeignKey(Country, chained_field="continent",  chained_model_field="continent", show_all=False, auto_choose=True, sort=True)
            name = models.CharField(max_length=255)
            city= ChainedForeignKey(City, chained_field="country",  chained_model_field="country", show_all=False, auto_choose=True, sort=True)
    name = models.CharField(max_length=255)
            def __str__(self):
                return self.name
    

    admin.py

    admin.site.register(Component)
    admin.site.register(Group)
    admin.site.register(Failure)
    admin.site.register(Neighborhood)
    

提交回复
热议问题