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
|
||||
|
||||
|
||||
class CollectionSerializer(serializers.ModelSerializer):
|
||||
"""Collection serializer"""
|
||||
class CollectionBaseSerializer(serializers.ModelSerializer):
|
||||
"""Collection base serializer"""
|
||||
# RESPONSE
|
||||
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
|
||||
block_size = serializers.JSONField()
|
||||
is_publish = serializers.BooleanField()
|
||||
|
|
@ -24,18 +37,13 @@ class CollectionSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = models.Collection
|
||||
fields = [
|
||||
'id',
|
||||
'name',
|
||||
'description_translated',
|
||||
fields = CollectionBaseSerializer.Meta.fields + [
|
||||
'start',
|
||||
'end',
|
||||
'image_url',
|
||||
'is_publish',
|
||||
'on_top',
|
||||
'country',
|
||||
'block_size',
|
||||
'slug',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ app_name = 'collection'
|
|||
|
||||
urlpatterns = [
|
||||
path('', views.CollectionHomePageView.as_view(), name='list'),
|
||||
path('<slug:slug>/', views.CollectionDetailView.as_view(), name='detail'),
|
||||
path('<slug:slug>/establishments/', views.CollectionEstablishmentListView.as_view(),
|
||||
name='detail'),
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,14 @@ from collection.serializers import common as serializers
|
|||
class CollectionViewMixin(generics.GenericAPIView):
|
||||
"""Mixin for Collection view"""
|
||||
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):
|
||||
|
|
@ -23,41 +30,22 @@ class GuideViewMixin(generics.GenericAPIView):
|
|||
|
||||
# Views
|
||||
# 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):
|
||||
"""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)\
|
||||
.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."""
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
lookup_field = 'slug'
|
||||
pagination_class = ProjectPageNumberPagination
|
||||
serializer_class = EstablishmentBaseSerializer
|
||||
lookup_field = 'slug'
|
||||
|
||||
def get_queryset(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user