@@ -612,19 +612,29 @@ class QuestSerializer(serializers.ModelSerializer):
612612
613613#### Performance improvements
614614
615- Be aware that using included resources without any form of prefetching ** WILL HURT PERFORMANCE** as it will introduce m* (n+1) queries.
615+ Be aware that using included resources without any form of prefetching ** WILL HURT PERFORMANCE** as it will introduce m\ * (n+1) queries.
616616
617617A viewset helper was designed to allow for greater flexibility and it is automatically available when subclassing
618- ` views.ModelViewSet `
619- ```
620- # When MyViewSet is called with ?include=author it will dynamically prefetch author and author.bio
621- class MyViewSet(viewsets.ModelViewSet):
618+ ` rest_framework_json_api.views.ModelViewSet ` :
619+ ``` python
620+ from rest_framework_json_api import views
621+
622+ # When MyViewSet is called with ?include=author it will dynamically prefetch author and author.bio
623+ class MyViewSet (views .ModelViewSet ):
622624 queryset = Book.objects.all()
623625 prefetch_for_includes = {
624- '__all__': [],
625- 'author': ['author', 'author__bio']
626- 'category.section': ['category']
627- }
626+ ' __all__' : [],
627+ ' author' : [' author' , ' author__bio' ],
628+ ' category.section' : [' category' ]
629+ }
630+ ```
631+
632+ An additional convenience DJA class exists for read-only views, just as it does in DRF.
633+ ``` python
634+ from rest_framework_json_api import views
635+
636+ class MyReadOnlyViewSet (views .ReadOnlyModelViewSet ):
637+ # ...
628638```
629639
630640The special keyword ` __all__ ` can be used to specify a prefetch which should be done regardless of the include, similar to making the prefetch yourself on the QuerySet.
0 commit comments