django chain select

前端 未结 2 956
攒了一身酷
攒了一身酷 2020-12-09 13:40

django-smart-selects is an elegant solution that enables Django developers to have chained select inputs in their forms. But as reported by developers in its list of issues,

相关标签:
2条回答
  • 2020-12-09 14:08

    I tried this and it works --- In the widgets.py file of django-smart-selects code, simply copy the section that deals with rendering javascript and delete it from the file. Remove the line that concatenates this (now deleted) javascript to the output.

    For your formsets, do the complete rendering yourself. That is, in your template don't just do {{ form }} or {{ formset }} or whatever, but explicitly lay out all individual fields by doing {{ form.field }} in a {% for form in formset.forms %} loop.

    Paste the javascript code that you copied over from widgets.py and customize it with the IDs in the javascript with {{ form.field.html_name }}

    Write in your own customized urls in the javascript, following the pattern in the code.

    Voila!

    0 讨论(0)
  • 2020-12-09 14:10

    make sure to use the formset's name/id/index in the element ID that is used by javascript, that way they'll still be unique

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