Skip to content

Instantly share code, notes, and snippets.

@imom0
Last active December 10, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imom0/4432602 to your computer and use it in GitHub Desktop.
Save imom0/4432602 to your computer and use it in GitHub Desktop.
request url: http://localhost:8000/myapp/comment/comment/?format=json&note=1&limit=3
{
"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/"
}
]
}
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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment