0

我对 Django-Tastypie 相当陌生,我正在查看下面的入门示例:http: //django-tastypie.readthedocs.org/en/latest/tutorial.html#hooking-up-the-resource-s

  1. http://127.0.0.1:8000/api/entry/?format=json
  2. http://127.0.0.1:8000/api/entry/1/?format=json
  3. http://127.0.0.1:8000/api/entry/schema/?format=json

是否可以允许包含某种格式的过滤条件的rest URL,用于过滤要返回的对象?

这意味着我必须在这个线程中做类似的事情:REST urls with sweetpie ?

4

1 回答 1

6

是的,Tastypie 允许开箱即用地过滤,因为您使用 ModelResource 作为资源的基类。您只需要声明可以过滤哪些属性,然后就可以开始了。

例如:

#resource definition
class MyResource(ModelResource):
    class Meta:
        filtering = {
            "slug": ('exact', 'startswith',),
            "title": ALL,
        }

# the request
GET /api/v1/myresource/?slug=myslug

有关详细信息,请参阅Tastypie 文档

于 2012-03-02T17:48:20.880 回答