2012-02-17 86 views
0

我相當新的Django的Tastypie Django的tastypie REST URL,我在看下面的入門例子: 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

是否可以允許包含特定格式的過濾標準的其餘URL,用於過濾要返回的對象?

這將意味着我必須做這樣的線程:REST urls with tastypie

回答

6

是的,由於您使用ModelResource作爲您的資源的基礎類,Tastypie允許過濾開箱。你只需要聲明哪些屬性可以過濾,然後你就可以走了。

例如:

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

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

看到Tastypie documentation瞭解更多詳情。