Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 311385e

Browse files
Include meta section for SerializerMethodResourceRelatedField(many=True) (#1162)
Fixes #572
1 parent 71508ef commit 311385e

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ any parts of the framework not mentioned in the documentation should generally b
4040
return value.name
4141
```
4242

43+
* `SerializerMethodResourceRelatedField(many=True)` relationship data now includes a meta section.
44+
4345
### Fixed
4446

4547
* Refactored handling of the `sort` query parameter to fix duplicate declaration in the generated schema definition

‎example/tests/integration/test_non_paginated_responses.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_multiple_entries_no_pagination(multiple_entries, client):
5151
"related": "http://testserver/entries/1/suggested/",
5252
"self": "http://testserver/entries/1/relationships/suggested",
5353
},
54+
"meta": {"count": 1},
5455
},
5556
"suggestedHyperlinked": {
5657
"links": {
@@ -106,6 +107,7 @@ def test_multiple_entries_no_pagination(multiple_entries, client):
106107
"related": "http://testserver/entries/2/suggested/",
107108
"self": "http://testserver/entries/2/relationships/suggested",
108109
},
110+
"meta": {"count": 1},
109111
},
110112
"suggestedHyperlinked": {
111113
"links": {

‎example/tests/integration/test_pagination.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_pagination_with_single_entry(single_entry, client):
5151
"related": "http://testserver/entries/1/suggested/",
5252
"self": "http://testserver/entries/1/relationships/suggested",
5353
},
54+
"meta": {"count": 0},
5455
},
5556
"suggestedHyperlinked": {
5657
"links": {

‎example/tests/test_filters.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ def test_search_keywords(self):
512512
{"type": "entries", "id": "11"},
513513
{"type": "entries", "id": "12"},
514514
],
515+
"meta": {"count": 11},
515516
},
516517
"suggestedHyperlinked": {
517518
"links": {

‎rest_framework_json_api/renderers.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from rest_framework_json_api import utils
2020
from rest_framework_json_api.relations import (
2121
HyperlinkedMixin,
22+
ManySerializerMethodResourceRelatedField,
2223
ResourceRelatedField,
2324
SkipDataMixin,
2425
)
@@ -152,6 +153,11 @@ def extract_relationships(cls, fields, resource, resource_instance):
152153
if not isinstance(field, SkipDataMixin):
153154
relation_data.update({"data": resource.get(field_name)})
154155

156+
if isinstance(field, ManySerializerMethodResourceRelatedField):
157+
relation_data.update(
158+
{"meta": {"count": len(resource.get(field_name))}}
159+
)
160+
155161
data.update({field_name: relation_data})
156162
continue
157163

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /