How to loop over form field choices and display associated model instance fields

前端 未结 8 931
广开言路
广开言路 2021-02-02 14:44

I have a ModelForm with a multiple choice field. The choices are populated instances of Hikers belonging to a specific Club.

I want to customize the way my form displays

8条回答
  •  甜味超标
    2021-02-02 15:06

    Maybe help someone.

    template.html

    
    
    {{ form.field_name.label_tag }} {% for pk, choice in form.field_name.field.widget.choices %}
    {% endfor %}
    {{ form.field_name.label_tag }} {% for pk, choice in form.field_name.field.widget.choices %}
    {% endfor %}

    How to custom checkbox and radio in Django using Bootstrap

提交回复
热议问题