added endpoint for retrieving collection detail information
This commit is contained in:
parent
ca9475b182
commit
8e3bb54508
|
|
@ -4,11 +4,24 @@ from collection import models
|
||||||
from location import models as location_models
|
from location import models as location_models
|
||||||
|
|
||||||
|
|
||||||
class CollectionSerializer(serializers.ModelSerializer):
|
class CollectionBaseSerializer(serializers.ModelSerializer):
|
||||||
"""Collection serializer"""
|
"""Collection base serializer"""
|
||||||
# RESPONSE
|
# RESPONSE
|
||||||
description_translated = serializers.CharField(read_only=True, allow_null=True)
|
description_translated = serializers.CharField(read_only=True, allow_null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Collection
|
||||||
|
fields = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'description_translated',
|
||||||
|
'image_url',
|
||||||
|
'slug',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionSerializer(CollectionBaseSerializer):
|
||||||
|
"""Collection serializer"""
|
||||||
# COMMON
|
# COMMON
|
||||||
block_size = serializers.JSONField()
|
block_size = serializers.JSONField()
|
||||||
is_publish = serializers.BooleanField()
|
is_publish = serializers.BooleanField()
|
||||||
|
|
@ -24,18 +37,13 @@ class CollectionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Collection
|
model = models.Collection
|
||||||
fields = [
|
fields = CollectionBaseSerializer.Meta.fields + [
|
||||||
'id',
|
|
||||||
'name',
|
|
||||||
'description_translated',
|
|
||||||
'start',
|
'start',
|
||||||
'end',
|
'end',
|
||||||
'image_url',
|
|
||||||
'is_publish',
|
'is_publish',
|
||||||
'on_top',
|
'on_top',
|
||||||
'country',
|
'country',
|
||||||
'block_size',
|
'block_size',
|
||||||
'slug',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ app_name = 'collection'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.CollectionHomePageView.as_view(), name='list'),
|
path('', views.CollectionHomePageView.as_view(), name='list'),
|
||||||
|
path('<slug:slug>/', views.CollectionDetailView.as_view(), name='detail'),
|
||||||
path('<slug:slug>/establishments/', views.CollectionEstablishmentListView.as_view(),
|
path('<slug:slug>/establishments/', views.CollectionEstablishmentListView.as_view(),
|
||||||
name='detail'),
|
name='detail'),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,14 @@ from collection.serializers import common as serializers
|
||||||
class CollectionViewMixin(generics.GenericAPIView):
|
class CollectionViewMixin(generics.GenericAPIView):
|
||||||
"""Mixin for Collection view"""
|
"""Mixin for Collection view"""
|
||||||
model = models.Collection
|
model = models.Collection
|
||||||
queryset = models.Collection.objects.all()
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
"""Override get_queryset method."""
|
||||||
|
return models.Collection.objects.published() \
|
||||||
|
.by_country_code(code=self.request.country_code) \
|
||||||
|
.filter_all_related_gt(3) \
|
||||||
|
.order_by('-on_top', '-modified')
|
||||||
|
|
||||||
|
|
||||||
class GuideViewMixin(generics.GenericAPIView):
|
class GuideViewMixin(generics.GenericAPIView):
|
||||||
|
|
@ -23,41 +30,22 @@ class GuideViewMixin(generics.GenericAPIView):
|
||||||
|
|
||||||
# Views
|
# Views
|
||||||
# Collections
|
# Collections
|
||||||
class CollectionListView(CollectionViewMixin, generics.ListAPIView):
|
|
||||||
"""List Collection view"""
|
|
||||||
permission_classes = (permissions.AllowAny,)
|
|
||||||
serializer_class = serializers.CollectionSerializer
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""Override get_queryset method"""
|
|
||||||
queryset = models.Collection.objects.published()\
|
|
||||||
.by_country_code(code=self.request.country_code)\
|
|
||||||
.order_by('-on_top', '-created')
|
|
||||||
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
|
|
||||||
class CollectionHomePageView(CollectionViewMixin, generics.ListAPIView):
|
class CollectionHomePageView(CollectionViewMixin, generics.ListAPIView):
|
||||||
"""List Collection view"""
|
"""List Collection view"""
|
||||||
permission_classes = (permissions.AllowAny,)
|
|
||||||
serializer_class = serializers.CollectionSerializer
|
serializer_class = serializers.CollectionSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""Override get_queryset method"""
|
|
||||||
queryset = models.Collection.objects.published()\
|
|
||||||
.by_country_code(code=self.request.country_code)\
|
|
||||||
.filter_all_related_gt(3)\
|
|
||||||
.order_by('-on_top', '-modified')
|
|
||||||
|
|
||||||
return queryset
|
class CollectionDetailView(CollectionViewMixin, generics.RetrieveAPIView):
|
||||||
|
"""Retrieve detail of Collection instance."""
|
||||||
|
lookup_field = 'slug'
|
||||||
|
serializer_class = serializers.CollectionBaseSerializer
|
||||||
|
|
||||||
|
|
||||||
class CollectionEstablishmentListView(CollectionListView):
|
class CollectionEstablishmentListView(CollectionHomePageView):
|
||||||
"""Retrieve list of establishment for collection."""
|
"""Retrieve list of establishment for collection."""
|
||||||
permission_classes = (permissions.AllowAny,)
|
lookup_field = 'slug'
|
||||||
pagination_class = ProjectPageNumberPagination
|
pagination_class = ProjectPageNumberPagination
|
||||||
serializer_class = EstablishmentBaseSerializer
|
serializer_class = EstablishmentBaseSerializer
|
||||||
lookup_field = 'slug'
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user