File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 77Add this mixin to a view to override ` get_queryset ` to automatically filter
88records by ` ids[]=1&ids[]=2 ` in URL query params.
99
10+ ## rest_framework_json_api.renderers.JSONRenderer
11+
12+ The ` JSONRenderer ` exposes a number of methods that you may override if you need
13+ highly custom rendering control.
14+
15+ #### extract_attributes
16+
17+ ` extract_attributes(fields, resource) `
18+
19+ Builds the ` attributes ` object of the JSON API resource object.
20+
21+ #### extract_relationships(fields, resource, resource_instance)
22+
23+ Builds the ` relationships ` top level object based on related serializers.
24+
25+ #### extract_included(fields, resource, resource_instance, included_resources)
26+
27+ Adds related data to the top level ` included ` key when the request includes ` ?include=example,example_field2 `
28+
29+ #### extract_meta(serializer, resource)
30+
31+ Gathers the data from serializer fields specified in ` meta_fields ` and adds it to the ` meta ` object.
32+
33+ #### extract_root_meta(serializer, resource, meta)
34+
35+ Calls a ` get_root_meta ` function on a serializer, if it exists.
36+
37+ #### build_json_resource_obj(fields, resource, resource_instance, resource_name)
38+
39+ Builds the resource object (type, id, attributes) and extracts relationships.
40+
Original file line number Diff line number Diff line change @@ -229,10 +229,28 @@ When set to pluralize:
229229Both ` JSON_API_PLURALIZE_RELATION_TYPE ` and ` JSON_API_FORMAT_RELATION_KEYS ` can be combined to
230230achieve different results.
231231
232+ ### Meta
233+
234+ You may add metadata to the rendered json in two different ways: ` meta_fields ` and ` get_root_meta ` .
235+
236+ On any ` rest_framework_json_api.serializers.ModelSerializer ` you may add a ` meta_fields `
237+ property to the ` Meta ` class. This behaves in the same manner as the default
238+ ` fields ` property and will cause ` SerializerMethodFields ` or model values to be
239+ added to the ` meta ` object within the same ` data ` as the serializer.
240+
241+ To add metadata to the top level ` meta ` object add:
242+
243+ ``` python
244+ def get_root_meta (self , obj ):
245+ return {
246+ ' size' : len (obj)
247+ }
248+ ```
249+ to the serializer. It must return a dict and will be merged with the existing top level ` meta ` .
250+
232251<!--
233252### Relationships
234253### Links
235254### Included
236255### Errors
237- ### Meta
238256-->
You can’t perform that action at this time.
0 commit comments