Django - 无法从查询集中检索多对多字段
我有以下代码:
exercises = Exercise.objects.filter(teacher=request.user.id).values('id', 'question', 'ans1', 'ans2', 'ans3', 'correct', 'unit', 'resol', 'theme', 'img')
这工作正常,但“主题”是一个多对多字段,格式返回 { ..., theme: value }
而不是 { ... , theme: [value1, value2] }
我应该实现什么才能获得所需的格式?
I have the following code:
exercises = Exercise.objects.filter(teacher=request.user.id).values('id', 'question', 'ans1', 'ans2', 'ans3', 'correct', 'unit', 'resol', 'theme', 'img')
This works fine, but the "theme" is a Many to Many Field, the format returns { ..., theme: value }
instead of { ..., theme: [value1, value2] }
What should I implement to get the desired format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过执行以下操作使其工作:
Made it work by doing the following: