Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How to make a TastyPie API with nested resources.
class ArticleResource(ModelResource):
class Meta:
authentication = Authentication()
authorization = DjangoAuthorization()
queryset = Article.objects.all()
class CategoryResource(ModelResource):
articles = fields.ToManyField('locations.api.Articles', 'articles', full=True)
class Meta:
authentication = Authentication()
authorization = DjangoAuthorization()
queryset = Category.objects.all()
class Article(models.Model):
category = models.ForeignKey('Category')
title = models.CharField(max_length=50)
content = models.TextField()
class Category(models.Model):
name = models.CharField(max_length=50)
v1_api = Api(api_name='v1')
v1_api.register(ArticleResource())
v1_api.register(CategoryResource())
urlpatterns = patterns('',
url(r'^api/', include(v1_api.urls)),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.