2

I have this as my resource

class AResource(ModelResource):
    content_object = GenericForeignKeyField({
        B: BResource,
    }, 'content_object')

class Meta:
    queryset = A.objects.all()
    filtering = {
        'content_type': ????,
    }

I want to filter this resource by id of resource BResource.
I try to filter by this url:
http://domain.com/api/v1/a/?content_type=/api/v1/b/7/
and http://domain.com/api/v1/a/?content_object=/api/v1/b/7/
but it didn't work.

How can we filter this?

4

1 回答 1

1

我知道这是一个较老的问题,但如果其他人发现它,我可以通过执行以下操作来解决同样的问题:

filtering = {
    'object_id': 'exact',
    'content_type': 'exact',
}

然后您的资源网址将如下所示:

http://domain.com/api/v1/a/?content_type=app_name,model_name&object_id=object_id

所以在 OP 的情况下,假设 BResource 在 myapp 并且模型名称是 b_model

http://domain.com/api/v1/a/?content_type=myapp,b_model&object_id=7
于 2014-03-17T22:56:25.033 回答