Returning Django comments for a Tastypie resource -


my django site has photo model represents photos in system , i'm using django.contrib.comments allow users comment on these. working fine i'd extend tastypie api allow accessing of comments photoresource using url /api/v1/photo/1/comments 1 id of photo. i'm able url work fine no matter sort of filtering i'm doing seem return complete set of comments rather set supplied photo. i've included cut down selection of current code api below:

class commentresource(modelresource):     user = fields.foreignkey(userresource, 'user')     class meta:        queryset = comment.objects.all()             filtering = {                 'user': all_with_relations,             }  class photoresource(modelresource):     user = fields.foreignkey(userresource, 'user')       class meta:         queryset = photo.objects.all()         filtering = {             'id': 'exact',             'user': all_with_relations         }      def prepend_urls(self):         return [url(r"^(?p<resource_name>%s)/(?p<pk>\w[\w/-]*)/comments%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_comments'), name="api_get_comments"),         ]      def get_comments(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 1 resource found @ uri.")         comment_resource = commentresource()         return comment_resource.get_list(request, object_pk=obj.id, content_type=contenttype.objects.get_for_model(photo)) 

as far can tell it's filter in last line isn't working. think complicated due contrib.comments using contenttypes link object being commented on guess it's possible tastypie can't cope with. i've tried bunch of variations on still doesn't work. felt pretty work:

ctype = contenttype.objects.get_for_model(obj) comment_resource = commentresource() return comment_resource.get_list(request, object_pk=obj.pk, content_type_id=ctype.id) 

but again comments returned.

does have ideas how (or if it's possible)?

usually instead of hacking photoresource filtering in commentresource instead. have enable filtering model , url this:

/api/v1/comment/?object__pk=1&content_type_id=2


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -