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: [
"/api/v1/subject/1/",
"/api/v1/subject/2/"
],
title: "Course 1"
}
I want to do something like:
/api/v1/course/1/subjects/?format=json
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
/api/v1/course/1/?format=json&fields=subjects
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With