Reputation: 251
I fairly new to Django-Tastypie, I looking at the Getting started example below: http://django-tastypie.readthedocs.org/en/latest/tutorial.html#hooking-up-the-resource-s
Would it be possible to allow rest URL which contains filter criteria in certain format, that would be used to filter objects to be returned?
That would mean I have to do something like in this thread: REST urls with tastypie ?
Upvotes: 0
Views: 3688
Reputation: 9948
Yes, Tastypie allows for filtering out of the box, given you're using ModelResource as the base clas for your Resources. You just need to declare which attributes can be filtered on and then you're good to go.
For example:
#resource definition
class MyResource(ModelResource):
class Meta:
filtering = {
"slug": ('exact', 'startswith',),
"title": ALL,
}
# the request
GET /api/v1/myresource/?slug=myslug
see Tastypie documentation for more details.
Upvotes: 6