@@ -612,19 +612,29 @@ class QuestSerializer(serializers.ModelSerializer):
612
612
613
613
#### Performance improvements
614
614
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.
616
616
617
617
A 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 ):
622
624
queryset = Book.objects.all()
623
625
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
+ # ...
628
638
```
629
639
630
640
The 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