Optimize queryset

This commit is contained in:
jhyns 2023-05-17 17:13:47 +09:00
parent d86855d579
commit 466e62066f

View File

@ -1,5 +1,5 @@
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.permissions import AllowAny, IsAdminUser, IsAuthenticated from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
@ -52,7 +52,12 @@ class ProductViewset(ActionBasedMixin, ModelViewSet):
class PostViewset(ActionBasedMixin, ModelViewSet): class PostViewset(ActionBasedMixin, ModelViewSet):
queryset = Post.objects.all() queryset = Post.objects.all().select_related(
"storage",
"product",
"author",
"product__brand",
)
serializer_class = PostSerializer serializer_class = PostSerializer
permission_classes = [IsAuthenticated, IsAuthorOrReadOnly] permission_classes = [IsAuthenticated, IsAuthorOrReadOnly]
permission_classes_map = { permission_classes_map = {