Skip to content

Instantly share code, notes, and snippets.

@turingmachine
Created November 4, 2011 17:16
Show Gist options
  • Select an option

  • Save turingmachine/1339892 to your computer and use it in GitHub Desktop.

Select an option

Save turingmachine/1339892 to your computer and use it in GitHub Desktop.
class IdeaResource(ModelResource):
comments = fields.ToManyField('atizo.apps.ideas.api.IdeaCommentResource', 'ideacomment_set')
def override_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/children%s$" % (self._meta.resource_name, trailing_slash()),
self.wrap_view('get_children'), name="api_get_children"
),
]
def get_children(self, request, **kwargs):
try:
obj = self.cached_obj_get(request=request, **self.remove_api_resource_names(kwargs))
except ObjectDoesNotExist:
return HttpGone()
except MultipleObjectsReturned:
return HttpMultipleChoices("More than one resource is found at this URI.")
child_resource = IdeaCommentResource()
return child_resource.get_detail(request, idea=obj.pk)
class Meta:
resource_name = 'ideas'
queryset = Idea.objects.all()
class IdeaCommentResource(ModelResource):
idea = fields.ForeignKey('atizo.apps.ideas.api.IdeaResource', 'idea')
class Meta():
resource_name = 'comments'
queryset = IdeaComment.objects.all()
filtering = {
'idea': ALL_WITH_RELATIONS,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment