Skip to content

Instantly share code, notes, and snippets.

@imom0
Last active December 10, 2015 12:08

Revisions

  1. imom0 revised this gist Jan 2, 2013. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions views.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    from tastypie import fields
    from tastypie.resources import ModelResource, ALL
    from myapp.models import Note, Comment

    class NoteResource(ModelResource):
    comments = fields.ToManyField('myapp.views.CommentResource',
    'comments', full=True)

    class Meta:
    queryset = Note.objects.all()


    class CommentResource(ModelResource):
    note = fields.ToOneField(NoteResource, 'note')

    class Meta:
    queryset = Comment.objects.all()
    filtering = {'note': ALL}
  2. imom0 created this gist Jan 2, 2013.
    29 changes: 29 additions & 0 deletions comment.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    {
    "meta": {
    "limit": 3,
    "next": "/myapp/comment/comment/?note=1&offset=3&limit=3&format=json",
    "offset": 0,
    "previous": null,
    "total_count": 4
    },
    "objects": [
    {
    "content": "comment 1",
    "id": "1",
    "note": "/myapp/note/note/1/",
    "resource_uri": "/myapp/comment/comment/1/"
    },
    {
    "content": "comment 3",
    "id": "3",
    "note": "/myapp/note/note/1/",
    "resource_uri": "/myapp/comment/comment/3/"
    },
    {
    "content": "comment 4",
    "id": "4",
    "note": "/myapp/note/note/1/",
    "resource_uri": "/myapp/comment/comment/4/"
    }
    ]
    }