Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions example/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
from example.serializers import (
BlogSerializer, EntrySerializer, AuthorSerializer, CommentSerializer)

from rest_framework_json_api.utils import format_drf_errors


class BlogViewSet(viewsets.ModelViewSet):
queryset = Blog.objects.all()
serializer_class = BlogSerializer


class BlogCustomViewSet(viewsets.ModelViewSet):
queryset = Blog.objects.all()
serializer_class = BlogSerializer

def handle_exception(self, exc):
return format_drf_errors(super(BlogCustomViewSet, self).handle_exception(exc), self.get_exception_handler_context(), exc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this into multiple lines, it's a bit long.

Also would you mind adding some comments to this function so devs reading this file for an example can easily understand that it is an optional override that enables JSON-API to work alongside the regular DRF format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do. I'll also add the other settings that can be set on the class itself - as a full setup example.



class EntryViewSet(viewsets.ModelViewSet):
queryset = Entry.objects.all()
resource_name = 'posts'
Expand Down