<s> from rest_framework import exceptions <EOL> from rest_framework import viewsets <EOL> import rest_framework . parsers <EOL> import rest_framework . renderers <EOL> import rest_framework_json_api . metadata <EOL> import rest_framework_json_api . parsers <EOL> import rest_framework_json_api . renderers <EOL> from rest_framework_json_api . views import RelationshipView <EOL> from example . models import Blog , Entry , Author , Comment <EOL> from example . serializers import ( <EOL> BlogSerializer , EntrySerializer , AuthorSerializer , CommentSerializer ) <EOL> from rest_framework_json_api . utils import format_drf_errors <EOL> HTTP_422_UNPROCESSABLE_ENTITY = <NUM_LIT> <EOL> class BlogViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = Blog . objects . all ( ) <EOL> serializer_class = BlogSerializer <EOL> class JsonApiViewSet ( viewsets . ModelViewSet ) : <EOL> """<STR_LIT>""" <EOL> parser_classes = [ <EOL> rest_framework_json_api . parsers . JSONParser , <EOL> rest_framework . parsers . FormParser , <EOL> rest_framework . parsers . MultiPartParser , <EOL> ] <EOL> renderer_classes = [ <EOL> rest_framework_json_api . renderers . JSONRenderer , <EOL> rest_framework . renderers . BrowsableAPIRenderer , <EOL> ] <EOL> metadata_class = rest_framework_json_api . metadata . JSONAPIMetadata <EOL> def handle_exception ( self , exc ) : <EOL> if isinstance ( exc , exceptions . ValidationError ) : <EOL> exc . status_code = HTTP_422_UNPROCESSABLE_ENTITY <EOL> response = super ( JsonApiViewSet , self ) . handle_exception ( exc ) <EOL> context = self . get_exception_handler_context ( ) <EOL> return format_drf_errors ( response , context , exc ) <EOL> class BlogCustomViewSet ( JsonApiViewSet ) : <EOL> queryset = Blog . objects . all ( ) <EOL> serializer_class = BlogSerializer <EOL> class EntryViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = Entry . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> def get_serializer_class ( self ) : <EOL> return EntrySerializer <EOL> class AuthorViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = Author . objects . all ( ) <EOL> serializer_class = AuthorSerializer <EOL> class CommentViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = Comment . objects . all ( ) <EOL> serializer_class = CommentSerializer <EOL> class EntryRelationshipView ( RelationshipView ) : <EOL> queryset = Entry . objects . all ( ) <EOL> class BlogRelationshipView ( RelationshipView ) : <EOL> queryset = Blog . objects . all ( ) <EOL> class CommentRelationshipView ( RelationshipView ) : <EOL> queryset = Comment . objects . all ( ) <EOL> class AuthorRelationshipView ( RelationshipView ) : <EOL> queryset = Author . objects . all ( ) <EOL> self_link_view_name = '<STR_LIT>' </s>
