【问题标题】:Tastypie using ToOneFields across two ForeignKey relationsTastypie 在两个 ForeignKey 关系中使用 ToOneFields
【发布时间】:2012-07-25 00:16:22
【问题描述】:

我正在尝试在我的资源中执行此操作...

thingy = fields.ToOneField(ThingyResource, 'whatzit__thingy')

即,遍历 fk。我在一个资源上,whos 模型对“whatzit”有一个 fk,而“whatzit”模型对“thingy”有一个 fk。

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

或者,是否有一种直接的方法来查询资源以获取对象的 uri?

【问题讨论】:

    标签: python django tastypie


    【解决方案1】:

    我想你只想这样做:

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

    然后像这样脱水:

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

    【讨论】:

      猜你喜欢
      • 2014-01-01
      • 2012-01-28
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      相关资源
      最近更新 更多