First make a TagResource
:
from taggit.models import Tag
class TagResource(ModelResource):
class Meta:
queryset = Tag.objects.all()
Then in your resource that got tags:
class FooResource(ModelResource):
tags = fields.ToManyField(TagResource, 'tags', # if your tag field is 'tags'
full = True)
class Meta:
queryset = Foo.objects.all()
It should work.
UPDATE
In order to filter the tag, you have to filter it through TagResource
, assuming your api name is v1
, the url is :
/api/v1/tag/?slug=anytagyouwant&format=json
Above url is for like : 'is anytagyouwant
exist?'
for 'get all foo that have anytagyouwant
tag'
/api/v1/foo/?tags__slug=anytagyouwant&format=json
Note, to be able to filter for certain fields, you have to declare it in your resource, using FooResource
as an example :
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
class FooResource(ModelResource):
tags = fields.ToManyField(TagResource, 'tags', # if your tag field is 'tags'
full = True)
class Meta:
queryset = Foo.objects.all()
filtering = dict(
tags = ALL,
# or
tags = ALL_WITH_RELATIONS,
)