Optimize query
This commit is contained in:
parent
990b15f1d7
commit
26b76c0b8c
18
apps/establishment/migrations/0093_auto_20200204_1120.py
Executable file
18
apps/establishment/migrations/0093_auto_20200204_1120.py
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.7 on 2020-02-04 11:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('establishment', '0092_merge_20200131_0835'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='establishment',
|
||||
name='status',
|
||||
field=models.PositiveSmallIntegerField(choices=[(0, 'Abandoned'), (1, 'Closed'), (2, 'Published'), (3, 'Unpicked'), (4, 'Waiting'), (5, 'Hidden'), (6, 'Deleted'), (7, 'Out of selection'), (8, 'Unpublished')], default=4, verbose_name='Status'),
|
||||
),
|
||||
]
|
||||
|
|
@ -134,6 +134,10 @@ class EstablishmentQuerySet(models.QuerySet):
|
|||
"""Return qs with related schedule."""
|
||||
return self.prefetch_related('schedule')
|
||||
|
||||
def with_reviews(self):
|
||||
"""Return qs with related reviews."""
|
||||
return self.prefetch_related('reviews')
|
||||
|
||||
def with_currency_related(self):
|
||||
"""Return qs with related """
|
||||
return self.prefetch_related('currency')
|
||||
|
|
|
|||
|
|
@ -424,6 +424,7 @@ class EstablishmentListRetrieveSerializer(EstablishmentBaseSerializer):
|
|||
'vintage_year',
|
||||
'reviews',
|
||||
'contact_phones',
|
||||
'public_mark'
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
|||
serializer_class = serializers.EstablishmentListRetrieveSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().with_schedule() \
|
||||
return super().get_queryset().with_schedule().with_reviews() \
|
||||
.with_extended_address_related().with_currency_related() \
|
||||
.with_certain_tag_category_related('category', 'restaurant_category') \
|
||||
.with_certain_tag_category_related('cuisine', 'restaurant_cuisine') \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user