【问题标题】:Filter GenericForeignKeyField in django tastypie在 django sweetpie 中过滤 GenericForeignKeyField
【发布时间】:2012-12-01 17:55:47
【问题描述】:

在 django-tastypie 资源中使用 GenericForeignKeyField,有没有办法根据 content_type 过滤结果?我想向 Meta 类添加一个过滤器,就像使用常规字段一样,但我无法使用 GenericForeignKeyField 来做到这一点。

【问题讨论】:

    标签: django tastypie


    【解决方案1】:

    通过将此方法添加到我的资源中,我最终使内容类型脱水

    def dehydrate(self,bundle):
        bundle.data['type'] = bundle.obj.content_type
        return bundle   
    

    然后我在客户端过滤了数据。这不是一个理想的解决方案,但现在已经足够了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 2013-07-11
      • 1970-01-01
      • 2013-01-01
      • 2012-01-01
      • 1970-01-01
      • 2013-01-09
      相关资源
      最近更新 更多