zubinmehta zubinmehta - 23 days ago 4x
JSON Question

django tastypie only fetch a particular field of a particular object

In tastypie my url: /api/v1/course/1/?format=json gives the following json:

created_on: "2012-02-27T08:00:54",
description: "this is course 1",
id: "1",
resource_uri: "/api/v1/course/1/",
subjects: [
title: "Course 1"

I want to do something like:


to get only the list of subjects for a given course. Is this possible?


I'm guessing you want to do something like this where you specify a fields parameter so users can request only the fields they want. In your case, a user would send the request


One way to implement this is to extend Tastypie to give you this functionality. Currently, the full_dehydrate method iterates over all fields and dehydrates each of them. You can add in a check to see if the user entered fields and if so, just skip the dehydrate phase for any fields that were not specified.