From 466e62066f6dad789f995a3b479875674c3161e5 Mon Sep 17 00:00:00 2001 From: jhyns Date: Wed, 17 May 2023 17:13:47 +0900 Subject: [PATCH] Optimize queryset --- market/viewsets.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/market/viewsets.py b/market/viewsets.py index fb21962..97d0667 100644 --- a/market/viewsets.py +++ b/market/viewsets.py @@ -1,5 +1,5 @@ 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.viewsets import ModelViewSet @@ -52,7 +52,12 @@ class ProductViewset(ActionBasedMixin, ModelViewSet): class PostViewset(ActionBasedMixin, ModelViewSet): - queryset = Post.objects.all() + queryset = Post.objects.all().select_related( + "storage", + "product", + "author", + "product__brand", + ) serializer_class = PostSerializer permission_classes = [IsAuthenticated, IsAuthorOrReadOnly] permission_classes_map = {