From 1d3cf9dac0ef1698b15ee76dfaf0d115a6b14181 Mon Sep 17 00:00:00 2001 From: "a.gorbunov" Date: Mon, 27 Jan 2020 06:41:52 +0000 Subject: [PATCH] select related before load --- apps/collection/models.py | 4 ++++ apps/collection/views/back.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/collection/models.py b/apps/collection/models.py index 0457f38d..8024effb 100644 --- a/apps/collection/models.py +++ b/apps/collection/models.py @@ -57,6 +57,10 @@ class CollectionQuerySet(RelatedObjectsCountMixin): """Returned only published collection""" return self.filter(is_publish=True) + def with_base_related(self): + """Select relate objects""" + return self.select_related('country') + class Collection(ProjectBaseMixin, CollectionDateMixin, TranslatedFieldsMixin, URLImageMixin): diff --git a/apps/collection/views/back.py b/apps/collection/views/back.py index 481f70da..032bafb3 100644 --- a/apps/collection/views/back.py +++ b/apps/collection/views/back.py @@ -75,7 +75,7 @@ class CollectionBackOfficeViewSet(mixins.CreateModelMixin, """ViewSet for Collection model for BackOffice users.""" permission_classes = (permissions.IsAuthenticated,) - queryset = models.Collection.objects.all() + queryset = models.Collection.objects.with_base_related() filter_backends = [DjangoFilterBackend, OrderingFilter] serializer_class = serializers.CollectionBackOfficeSerializer bind_object_serializer_class = serializers.CollectionBindObjectSerializer