Django反向关系问题

发布于 2024-09-07 22:58:13 字数 333 浏览 2 评论 0原文

我正在尝试编写一个反向关系来获取与每个问题相关的答案数量,但我得到的只是“否定投票”,该问题重复多次,而我不明白为什么会这样。 t 显示票数而不是票数。 我的代码:

{% for object in object.voteupanswer_set.all %}
Positive votes:{{ object.answer.count }}
{% endfor %}
{% for object in object.votedownanswer_set.all %}
Negative votes:{{ votedownanswer.count }}
{% endfor %}

谢谢

I'm trying to write a reverse relationship for taking the number of answers asociated to each question, but all i get is 'Negative voting' repeating as many times as the question is voted negatively, and i don't get why it doesn't display the number of votes instead of that.
my code:

{% for object in object.voteupanswer_set.all %}
Positive votes:{{ object.answer.count }}
{% endfor %}
{% for object in object.votedownanswer_set.all %}
Negative votes:{{ votedownanswer.count }}
{% endfor %}

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2024-09-14 22:58:13

因为您应该显示计数,而不是迭代每个条目。

Negative votes: {{ object.votedownanswer_set.count }}

Because you should be showing the count, not iterating over each of the entries.

Negative votes: {{ object.votedownanswer_set.count }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文