last comment for mobile establishment detail
This commit is contained in:
parent
dee353199d
commit
69b40f21b7
|
|
@ -251,6 +251,15 @@ class EstablishmentQuerySet(models.QuerySet):
|
||||||
return self.filter(id__in=subquery_filter_by_distance) \
|
return self.filter(id__in=subquery_filter_by_distance) \
|
||||||
.order_by('-reviews__published_at')
|
.order_by('-reviews__published_at')
|
||||||
|
|
||||||
|
def prefetch_comments(self):
|
||||||
|
"""Prefetch last comment."""
|
||||||
|
from comment.models import Comment
|
||||||
|
return self.prefetch_related(
|
||||||
|
models.Prefetch('comments',
|
||||||
|
queryset=Comment.objects.exclude(is_publish=False).order_by('-created'),
|
||||||
|
to_attr='comments_prefetched')
|
||||||
|
)
|
||||||
|
|
||||||
def prefetch_actual_employees(self):
|
def prefetch_actual_employees(self):
|
||||||
"""Prefetch actual employees."""
|
"""Prefetch actual employees."""
|
||||||
return self.prefetch_related(
|
return self.prefetch_related(
|
||||||
|
|
@ -614,6 +623,11 @@ class Establishment(GalleryModelMixin, ProjectBaseMixin, URLImageMixin,
|
||||||
def artisan_category_indexing(self):
|
def artisan_category_indexing(self):
|
||||||
return self.tags.filter(category__index_name='shop_category')
|
return self.tags.filter(category__index_name='shop_category')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_comment(self):
|
||||||
|
if hasattr(self, 'comments_prefetched'):
|
||||||
|
return self.comments_prefetched[0]
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentNoteQuerySet(models.QuerySet):
|
class EstablishmentNoteQuerySet(models.QuerySet):
|
||||||
"""QuerySet for model EstablishmentNote."""
|
"""QuerySet for model EstablishmentNote."""
|
||||||
|
|
|
||||||
|
|
@ -401,6 +401,19 @@ class EstablishmentDetailSerializer(EstablishmentBaseSerializer):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class MobileEstablishmentDetailSerializer(EstablishmentDetailSerializer):
|
||||||
|
"""Serializer for Establishment model for mobiles."""
|
||||||
|
|
||||||
|
last_comment = comment_serializers.CommentRUDSerializer(allow_null=True)
|
||||||
|
|
||||||
|
class Meta(EstablishmentDetailSerializer.Meta):
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
fields = EstablishmentDetailSerializer.Meta.fields + [
|
||||||
|
'last_comment',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentSimilarSerializer(EstablishmentBaseSerializer):
|
class EstablishmentSimilarSerializer(EstablishmentBaseSerializer):
|
||||||
"""Serializer for Establishment model."""
|
"""Serializer for Establishment model."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ urlpatterns = [
|
||||||
path('', views.EstablishmentListView.as_view(), name='list'),
|
path('', views.EstablishmentListView.as_view(), name='list'),
|
||||||
path('recent-reviews/', views.EstablishmentRecentReviewListView.as_view(),
|
path('recent-reviews/', views.EstablishmentRecentReviewListView.as_view(),
|
||||||
name='recent-reviews'),
|
name='recent-reviews'),
|
||||||
path('slug/<slug:slug>/', views.EstablishmentRetrieveView.as_view(), name='detail'),
|
|
||||||
path('slug/<slug:slug>/similar/', views.EstablishmentSimilarListView.as_view(), name='similar'),
|
path('slug/<slug:slug>/similar/', views.EstablishmentSimilarListView.as_view(), name='similar'),
|
||||||
path('slug/<slug:slug>/comments/', views.EstablishmentCommentListView.as_view(), name='list-comments'),
|
path('slug/<slug:slug>/comments/', views.EstablishmentCommentListView.as_view(), name='list-comments'),
|
||||||
path('slug/<slug:slug>/comments/create/', views.EstablishmentCommentCreateView.as_view(),
|
path('slug/<slug:slug>/comments/create/', views.EstablishmentCommentCreateView.as_view(),
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ from establishment import views
|
||||||
from establishment.urls.common import urlpatterns as common_urlpatterns
|
from establishment.urls.common import urlpatterns as common_urlpatterns
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('geo/', views.EstablishmentNearestRetrieveView.as_view(), name='nearest-establishments-list')
|
path('geo/', views.EstablishmentNearestRetrieveView.as_view(), name='nearest-establishments-list'),
|
||||||
|
path('slug/<slug:slug>/', views.EstablishmentMobileRetrieveView.as_view(), name='mobile-detail'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns.extend(common_urlpatterns)
|
urlpatterns.extend(common_urlpatterns)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
"""Establishment app web urlconf."""
|
"""Establishment app web urlconf."""
|
||||||
from establishment.urls.common import urlpatterns as common_urlpatterns
|
from establishment.urls.common import urlpatterns as common_urlpatterns
|
||||||
|
from django.urls import path
|
||||||
|
from establishment import views
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = []
|
urlpatterns = [
|
||||||
|
path('slug/<slug:slug>/', views.EstablishmentRetrieveView.as_view(), name='web-detail'),
|
||||||
|
]
|
||||||
|
|
||||||
urlpatterns.extend(common_urlpatterns)
|
urlpatterns.extend(common_urlpatterns)
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,13 @@ class EstablishmentRetrieveView(EstablishmentMixinView, generics.RetrieveAPIView
|
||||||
return super().get_queryset().with_extended_related()
|
return super().get_queryset().with_extended_related()
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishmentMobileRetrieveView(EstablishmentRetrieveView):
|
||||||
|
serializer_class = serializers.MobileEstablishmentDetailSerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return super().get_queryset().prefetch_comments()
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentRecentReviewListView(EstablishmentListView):
|
class EstablishmentRecentReviewListView(EstablishmentListView):
|
||||||
"""List view for last reviewed establishments."""
|
"""List view for last reviewed establishments."""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user