djangomany-to-manymanytomanyfield

How can I display only selected options of a fild type ManyToMany - django


Good morning, I need to display the values selected in the manytomany field named "sfide" in a table I will build with html, how can I do it? thanks

I also attach the image of the class "Profilo" with the ManyToMany field "sfide" enter image description here


Solution

  • I found the answer:

                <table>
                <tr>
                    <td>
                        <h4>Sfide Scelte</h4>
                    </td>
                </tr>
                {% for sfida in user.profile.sfide.all %}
                <tr>
                    <td>{{ sfida.sfida }}</td>
                </tr>
                {% endfor %}
            </table>