added prefetch select related
This commit is contained in:
parent
9e237d4657
commit
469f7bdf4c
|
|
@ -16,6 +16,7 @@ from phonenumber_field.modelfields import PhoneNumberField
|
|||
from collection.models import Collection
|
||||
from location.models import Address
|
||||
from main.models import Award
|
||||
from tag.models import Tag, TagCategory
|
||||
from review.models import Review
|
||||
from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
||||
TranslatedFieldsMixin, BaseAttributes)
|
||||
|
|
@ -24,6 +25,18 @@ from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin,
|
|||
class EstablishmentTypeQuerySet(models.QuerySet):
|
||||
"""QuerySet for model EstablishmentType."""
|
||||
|
||||
def with_base_related(self):
|
||||
"""Return QuerySet with base related."""
|
||||
return self.prefetch_related(
|
||||
models.Prefetch('tag_categories',
|
||||
EstablishmentTypeTagCategory.objects.select_related('tag_category')),
|
||||
models.Prefetch('establishmentsubtype_set',
|
||||
EstablishmentSubType.objects.prefetch_related(
|
||||
models.Prefetch(
|
||||
'tag_categories',
|
||||
EstablishmentSubTypeTagCategory.objects.select_related('tag_category'))))
|
||||
)
|
||||
|
||||
|
||||
# todo: establishment type&subtypes check
|
||||
class EstablishmentType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||
|
|
@ -35,6 +48,8 @@ class EstablishmentType(TranslatedFieldsMixin, ProjectBaseMixin):
|
|||
help_text='{"en-GB":"some text"}')
|
||||
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
||||
|
||||
objects = EstablishmentTypeQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ class EstablishmentTypeRUDView(generics.RetrieveUpdateDestroyAPIView):
|
|||
class EstablishmentTypeTagListView(generics.ListAPIView):
|
||||
"""List of tags with categories by establishment type."""
|
||||
serializer_class = serializers.EstablishmentTagsByType
|
||||
queryset = models.EstablishmentType.objects.all()
|
||||
queryset = models.EstablishmentType.objects.with_base_related()
|
||||
filter_class = EstablishmentTypeTagFilter
|
||||
permission_classes = (permissions.AllowAny, )
|
||||
pagination_class = None
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user