相关模型上的 Django OneToMany 表单

发布于 2024-11-19 12:08:20 字数 175 浏览 0 评论 0原文

我在两个模型之间创建了一对多关系。型号 有外键我可以毫无问题地使用他们的表单集,但是 现在我想通过模型的形式来填充这个关系 有“很多”,我知道我可以使用 *_set 检索它,但是如何 我可以创建此数据的 MultipleChoiceField 表单元素吗?

感谢您的帮助!

问候,

蒂亚戈

I've created a onetomany relationship between two models. The model
that has the foreignkey I can use their formset without problems, but
now I want to fill this relation through the form of the model that
has the "many", I know I can retrieve it using the *_set, but how
can I create a MultipleChoiceField form element of this data?

Thanks for any help!

Regards,

Thiago

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

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

发布评论

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

评论(1

陌伤浅笑 2024-11-26 12:08:20

查看 处理字段的文档关系。您可以使用 ModelMultipleChoiceField -- 它本质上是一个从查询集中获取选择的 MultipleChoiceField

Have a look at the docs for fields which handle relationships. You could use a ModelMultipleChoiceField -- it's essentially a MultipleChoiceField that takes its choices from a queryset.

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