django smart_selects, second level won't populate

前端 未结 3 420
无人共我
无人共我 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条回答
  • 2021-01-25 04:42

    html.file

    include the following if you are using forms

    <script src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
    <script src="{% static 'smart-selects/admin/js/chainedm2m.js' %}"></script>
    

    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)
    
    0 讨论(0)
  • 2021-01-25 04:50

    UPDATE - MAY 2017

    include this tag right after jQuery version 2 . It works perfrectly well in Django 1.10 and 1.11 version using python 3.5.2. Hope this helps you

    <script type="text/javascript" src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
    <script type="text/javascript" src="{% static 'smart-selects/admin/js/chainedm2m.js' %}"></script>
    <script type="text/javascript" src="{% static 'smart-selects/admin/js/bindfields.js' %}"></script>
    
    0 讨论(0)
  • 2021-01-25 04:55

    This looks alright. The problem might be that you haven't set up the smart_selects urls, or perhaps you're missing the javascript in your actual page.

    0 讨论(0)
提交回复
热议问题