tastypie - I want an EmbeddedListField of comments to show up only when I 'GET' a single post and not when I 'GET' a list of posts -
i have mongodb document 'post' has embeddedlistfield of 'comments'. i'm using tastypie build api layer , want comments listed body fields when single post requested. when list of posts requested not want show full comment body kill app's performance. have in resource file:
comments = tastypie_mongoengine_fields.embeddedlistfield(of='api_core.resources.embeddedcommentresource', attribute='comments', full=true, null=true) what can this? not want create 2 entry points 'post_entry' , 'post_list' bad design consumer of apis.
i did simple check in dehydrate method:
def dehydrate(self, bundle): if self.get_resource_uri(bundle) != bundle.request.path: bundle.data['comments_count'] = len(bundle.data['comments']) del bundle.data['comments'] bundle.data['user_id'] = bundle.data['user'].data['id'] bundle.data['user_name'] = bundle.data['user'].data['first_name'] bundle.data['user_uri'] = bundle.data['user'].data['resource_uri'] del bundle.data['user'] return bundle
Comments
Post a Comment