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 04a531a

Browse files
[FEATURE]: support using get_serializer_class on view
1 parent 697adf1 commit 04a531a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

‎example/views.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ class BlogViewSet(viewsets.ModelViewSet):
1212

1313
class EntryViewSet(viewsets.ModelViewSet):
1414
queryset = Entry.objects.all()
15-
serializer_class = EntrySerializer
1615
resource_name = 'posts'
1716

17+
def get_serializer_class(self):
18+
return EntrySerializer
19+
1820

1921
class AuthorViewSet(viewsets.ModelViewSet):
2022
queryset = Author.objects.all()

‎rest_framework_json_api/serializers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def validate_path(serializer_class, field_path, path):
9494
included_resources = include_resources_param.split(',')
9595
for included_field_name in included_resources:
9696
included_field_path = included_field_name.split('.')
97-
this_serializer_class = view.serializer_class
97+
this_serializer_class = view.get_serializer_class()
9898
# lets validate the current path
9999
validate_path(this_serializer_class, included_field_path, included_field_name)
100100

0 commit comments

Comments
(0)

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