base related qs for cities
This commit is contained in:
parent
b6bfc51aad
commit
f5da5f71a3
|
|
@ -353,7 +353,7 @@ class EstablishmentNoteListCreateView(EstablishmentMixinViews,
|
|||
|
||||
lookup_field = 'slug'
|
||||
serializer_class = serializers.EstablishmentNoteListCreateSerializer
|
||||
|
||||
permission_classes = (permissions.AllowAny, )
|
||||
def get_object(self):
|
||||
"""Returns the object the view is displaying."""
|
||||
establishment_qs = models.Establishment.objects.all()
|
||||
|
|
|
|||
|
|
@ -139,6 +139,9 @@ class CityQuerySet(models.QuerySet):
|
|||
"""Return establishments by country code"""
|
||||
return self.filter(country__code=code)
|
||||
|
||||
def with_base_related(self):
|
||||
return self.prefetch_related('country', 'region', 'region__country')
|
||||
|
||||
|
||||
class City(models.Model):
|
||||
"""Region model."""
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class CityListCreateView(common.CityViewMixin, generics.ListCreateAPIView):
|
|||
def get_queryset(self):
|
||||
"""Overridden method 'get_queryset'."""
|
||||
qs = models.City.objects.all().annotate(locale_name=KeyTextTransform(get_current_locale(), 'name_translated'))\
|
||||
.order_by('locale_name')
|
||||
.order_by('locale_name').with_base_related()
|
||||
if self.request.country_code:
|
||||
qs = qs.by_country_code(self.request.country_code)
|
||||
return qs
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class RegionViewMixin(generics.GenericAPIView):
|
|||
class CityViewMixin(generics.GenericAPIView):
|
||||
"""View Mixin for model City"""
|
||||
model = models.City
|
||||
queryset = models.City.objects.all()
|
||||
queryset = models.City.objects.with_base_related()
|
||||
|
||||
|
||||
class AddressViewMixin(generics.GenericAPIView):
|
||||
|
|
@ -101,7 +101,7 @@ class CityListView(CityViewMixin, generics.ListAPIView):
|
|||
def get_queryset(self):
|
||||
qs = super().get_queryset()
|
||||
if self.request.country_code:
|
||||
qs = qs.by_country_code(self.request.country_code)
|
||||
qs = qs.by_country_code(self.request.country_code).with_base_related()
|
||||
return qs
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user