Commit 75bbbf1b authored by Florent Chehab's avatar Florent Chehab

Removed extend_queryset and my_model_queryset; use of standard super

parent 60184081
Pipeline #35533 passed with stages
in 5 minutes and 15 seconds
......@@ -40,13 +40,6 @@ class MyModelViewSet(viewsets.ModelViewSet):
Extended default rest framework behavior
to prefetch some table and enhance performances
"""
self.my_model_queryset = self.queryset.prefetch_related(
return self.queryset.prefetch_related(
"moderated_by", "updated_by", "pending_moderation"
)
return self.extend_queryset()
def extend_queryset(self):
"""
Function to extend get_queryset when subclassing
"""
return self.my_model_queryset
......@@ -41,8 +41,8 @@ class TaggedItemViewSet(BasicModuleViewSet):
Tagged item viewset
"""
def extend_queryset(self):
def get_queryset(self):
"""
Extend the queryset for a bit of optimization
"""
return self.my_model_queryset.prefetch_related("tag")
return super().get_queryset().prefetch_related("tag")
......@@ -33,6 +33,6 @@ class CampusTaggedItemViewSet(TaggedItemViewSet):
queryset = CampusTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CampusTaggedItemSerializer
def extend_queryset(self):
def get_queryset(self):
campus_id = self.kwargs["campus_id"]
return self.my_model_queryset.filter(campus=campus_id).distinct()
return super().get_queryset().filter(campus=campus_id).distinct()
......@@ -34,6 +34,6 @@ class CityTaggedItemViewSet(TaggedItemViewSet):
queryset = CityTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CityTaggedItemSerializer
def extend_queryset(self):
def get_queryset(self):
city_id = self.kwargs["city_id"]
return self.my_model_queryset.filter(city=city_id).distinct()
return super().get_queryset().filter(city=city_id).distinct()
......@@ -30,6 +30,6 @@ class CountryDriViewSet(BasicModuleViewSet):
queryset = CountryDri.objects.all() # pylint: disable=E1101
serializer_class = CountryDriSerializer
def extend_queryset(self):
def get_queryset(self):
country_id = self.kwargs["country_id"]
return self.my_model_queryset.filter(countries__pk=country_id).distinct()
return super().get_queryset().filter(countries__pk=country_id).distinct()
......@@ -28,6 +28,6 @@ class CountryScholarshipViewSet(ScholarshipViewSet):
queryset = CountryScholarship.objects.all() # pylint: disable=E1101
serializer_class = CountryScholarshipSerializer
def extend_queryset(self):
def get_queryset(self):
country_id = self.kwargs["country_id"]
return self.my_model_queryset.filter(countries__pk=country_id).distinct()
return super().get_queryset().filter(countries__pk=country_id).distinct()
......@@ -33,6 +33,6 @@ class CountryTaggedItemViewSet(TaggedItemViewSet):
queryset = CountryTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = CountryTaggedItemSerializer
def extend_queryset(self):
def get_queryset(self):
country_id = self.kwargs["country_id"]
return self.my_model_queryset.filter(country=country_id).distinct()
return super().get_queryset().filter(country=country_id).distinct()
......@@ -30,6 +30,6 @@ class UniversityDriViewSet(BasicModuleViewSet):
queryset = UniversityDri.objects.all() # pylint: disable=E1101
serializer_class = UniversityDriSerializer
def extend_queryset(self):
def get_queryset(self):
univ_id = self.kwargs["univ_id"]
return self.my_model_queryset.filter(universities__pk=univ_id).distinct()
return super().get_queryset().filter(universities__pk=univ_id).distinct()
......@@ -32,6 +32,6 @@ class UniversityScholarshipViewSet(ScholarshipViewSet):
queryset = UniversityScholarship.objects.all() # pylint: disable=E1101
serializer_class = UniversityScholarshipSerializer
def extend_queryset(self):
def get_queryset(self):
univ_id = self.kwargs["univ_id"]
return self.my_model_queryset.filter(universities__pk=univ_id).distinct()
return super().get_queryset().filter(universities__pk=univ_id).distinct()
......@@ -33,6 +33,6 @@ class UniversityTaggedItemViewSet(TaggedItemViewSet):
queryset = UniversityTaggedItem.objects.all() # pylint: disable=E1101
serializer_class = UniversityTaggedItemSerializer
def extend_queryset(self):
def get_queryset(self):
univ_id = self.kwargs["univ_id"]
return self.my_model_queryset.filter(university__pk=univ_id).distinct()
return super().get_queryset().filter(university__pk=univ_id).distinct()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment