如何仅显示Django中ManyToMany字段类型的选定选项?

huangapple go评论47阅读模式
英文:

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

问题

早上好,我需要在我将用HTML构建的表格中显示名为“sfide”的ManyToMany字段中选择的值,我该如何做?谢谢。

我还附上了“Profilo”类的图像,其中包含ManyToMany字段“sfide”。查看图片描述

英文:

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

答案1

得分: 0

我找到了答案:

<table>
    <tr>
        <td>
            <h4>挑战选择</h4>
        </td>
    </tr>
    {% for sfida in user.profile.sfide.all %}
    <tr>
        <td>{{ sfida.sfida }}</td>
    </tr>
    {% endfor %}
</table>
英文:

I found the answer:

            &lt;table&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;h4&gt;Sfide Scelte&lt;/h4&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            {% for sfida in user.profile.sfide.all %}
            &lt;tr&gt;
                &lt;td&gt;{{ sfida.sfida }}&lt;/td&gt;
            &lt;/tr&gt;
            {% endfor %}
        &lt;/table&gt;

huangapple
  • 本文由 发表于 2023年5月6日 20:01:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188757.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定