相关模型上的 Django OneToMany 表单
我在两个模型之间创建了一对多关系。型号 有外键我可以毫无问题地使用他们的表单集,但是 现在我想通过模型的形式来填充这个关系 有“很多”,我知道我可以使用 *_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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 处理字段的文档关系。您可以使用
ModelMultipleChoiceField
-- 它本质上是一个从查询集中获取选择的MultipleChoiceField
。Have a look at the docs for fields which handle relationships. You could use a
ModelMultipleChoiceField
-- it's essentially aMultipleChoiceField
that takes its choices from a queryset.