Tastypie在两个ForeignKey关系中使用ToOneFields



我正在我的资源中尝试这样做。。。

thingy=字段。ToOneField(ThingyResource,'whatzit_thingy')

也就是说,遍历一个fk。我在一个资源上,它的模型从fk到"whatzit",而"whatzit"模型从fk到"thingy"。

这种语法不起作用——有没有办法做到这一点,或者没有建议,或者其他?

或者,有没有一种直接的方法可以查询资源中对象的uri?

我想你只想这样做:

whatzit = fields.ToOneField(WhatzitResource, 'whatzit')

然后像这样脱水:

def dehydrate(self, bundle):
    bundle.data['thingy'] = whatzit.thingy
    return bundle

最新更新