django 中 fk 的迭代
如果我现在在 django 模型中有这样的表,
person
------
id
name
worker
------
personid
jobid
job
---
id
desc
wage
w=Worker.objects.filter(<some sort of filter)
我想要在 w
中相关的所有 person
给出了 w
我无法使用该语句。
最终我想返回一个代表 dict
的 json 字符串 以 idperson
作为键,以 {"job":jobid,"wage":wage}
作为jobs
列表中该键的一个值
if I have table like this represented in django model
person
------
id
name
worker
------
personid
jobid
job
---
id
desc
wage
w=Worker.objects.filter(<some sort of filter)
now I want all persons
that are related in w
w
is given I can not use that statement.
eventually I want to return a json string that represents a dict
with idperson
as key and {"job":jobid,"wage":wage}
as
one value in list of jobs
for that key
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够输入您想要的任何对象集合。它应该看起来像:
从这里当然你可以迭代你的工作人员并建立你的列表:
You should be able to us an in, with any collection of objects you wish. It should look something like:
From here of course you could iterate over your workers and build up your list:
http://docs.djangoproject.com/en/ 1.3/topics/db/queries/#following-relationships-backward
信用支持
http://docs.djangoproject.com/en/1.3/topics/db/queries/#following-relationships-backward
credit to support