Skip to content

Commit

Permalink
impfix N+1 problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Atikiho committed Dec 11, 2024
1 parent d12f7f8 commit cbe7c21
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Meta:
"cinema_hall",
"movie",
)
read_only_fields = ("id",)


class MovieSessionDetailSerializer(serializers.ModelSerializer):
Expand Down
4 changes: 2 additions & 2 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CinemaHallViewSet(viewsets.ModelViewSet):


class MovieViewSet(viewsets.ModelViewSet):
queryset = Movie.objects.all()
queryset = Movie.objects.prefetch_related()

def get_serializer_class(self):
if self.action == "list":
Expand All @@ -45,7 +45,7 @@ def get_serializer_class(self):


class MovieSessionViewSet(viewsets.ModelViewSet):
queryset = MovieSession.objects.all()
queryset = MovieSession.objects.select_related("movie", "cinema_hall")

def get_serializer_class(self):
if self.action == "retrieve":
Expand Down

0 comments on commit cbe7c21

Please sign in to comment.