-
Notifications
You must be signed in to change notification settings - Fork 299
Closed
Labels
@scottfisk
Description
With #250 pulled in we now have options to include relations to form compound documents:
- Include resources related to the primary data by default.
- Include resources related to the primary data through use of a request parameter which customizes which related resources should be returned
Example Current Implementation
- default include
posts
class UserSerializer(serializers.Serializer): name = serializers.CharField(max_length=200) # PostSerializer included directly on the serializer posts = PostSerializer(many=True, read_only=True) class JSONAPIMeta: # included_resources specifys resources to include by default included_resources = ['posts']
- param include
posts
class UserSerializer(serializers.Serializer): name = serializers.CharField(max_length=200) # PostSerializer NOT included directly on the serializer, ResourceRelatedField is # specified as default posts = relations.ResourceRelatedField( source='post_set', many=True, read_only=True) # specifies serializer to use when passing in the `include` param included_serializers = { 'posts': PostSerializer, }
We should probably document this. We can even copy the examples above with a bit of explanation.