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

前端 未结 8 825
广开言路
广开言路 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 15:21

    Easiest would be if you define the whole form in a HTML template. You should be able to iterate over a field's values in a template like that:

    {% for value, text in form.hikers.field.choices %}
        {{ value }}: {{ text }}
    {% endfor %}
    

提交回复
热议问题