REST style resources using tastypie

24 views Asked by At

I am using django and let's say have two models, Comment & News. Now, Comment has a field news = models.ForeignKey(News), i.e. each news has some comments associated with it. REST way of GETing these resources would be /api/v1/news/news-id/comments. But how do I specify such url structure in tastypie.

Currently in my api.py, I have

class CommentResource(ModelResource):
    news = fields.ForeignKey(NewsResource, 'news')
    class Meta:
        resource_name = 'comments'

so, I have to access comments here: /api/v1/comments/. How do I achieve what I want?

0

There are 0 answers