added filter collection by country code from cookies
This commit is contained in:
parent
4cceb62d49
commit
6558c84be9
|
|
@ -28,9 +28,9 @@ class CollectionDateMixin(models.Model):
|
|||
class CollectionQuerySet(models.QuerySet):
|
||||
"""QuerySet for model Collection"""
|
||||
|
||||
def by_country(self, country):
|
||||
"""Filter collection by country."""
|
||||
return self.filter(country=country)
|
||||
def by_country_code(self, code):
|
||||
"""Filter collection by country code."""
|
||||
return self.filter(country__code=code)
|
||||
|
||||
def published(self):
|
||||
"""Returned only published collection"""
|
||||
|
|
|
|||
|
|
@ -8,34 +8,34 @@ app_name = 'collection'
|
|||
urlpatterns = [
|
||||
path('list/', views.CollectionListView.as_view(),
|
||||
name='collections_list'),
|
||||
path('create/', views.CollectionCreateView.as_view(),
|
||||
name='collection_create'),
|
||||
path('<int:pk>/', views.CollectionRetrieveView.as_view(),
|
||||
name='collection_retrieve'),
|
||||
path('<int:pk>/delete/', views.CollectionDestroyView.as_view(),
|
||||
name='collection_destroy'),
|
||||
path('<int:pk>/update/', views.CollectionUpdateView.as_view(),
|
||||
name='collection_update'),
|
||||
# path('create/', views.CollectionCreateView.as_view(),
|
||||
# name='collection_create'),
|
||||
# path('<int:pk>/', views.CollectionRetrieveView.as_view(),
|
||||
# name='collection_retrieve'),
|
||||
# path('<int:pk>/delete/', views.CollectionDestroyView.as_view(),
|
||||
# name='collection_destroy'),
|
||||
# path('<int:pk>/update/', views.CollectionUpdateView.as_view(),
|
||||
# name='collection_update'),
|
||||
|
||||
path('collection_items/', views.CollectionItemListView.as_view(),
|
||||
name='collection_items_list'),
|
||||
path('collection_items/create/', views.CollectionItemCreateView.as_view(),
|
||||
name='collection_items_create'),
|
||||
path('collection_items/<int:pk>/', views.CollectionItemRetrieveView.as_view(),
|
||||
name='collection_items_retrieve'),
|
||||
path('collection_items/<int:pk>/delete/', views.CollectionDestroyView.as_view(),
|
||||
name='collection_items_destroy'),
|
||||
path('collection_items/<int:pk>/update/', views.CollectionItemUpdateView.as_view(),
|
||||
name='collection_items_update'),
|
||||
# path('collection_items/create/', views.CollectionItemCreateView.as_view(),
|
||||
# name='collection_items_create'),
|
||||
# path('collection_items/<int:pk>/', views.CollectionItemRetrieveView.as_view(),
|
||||
# name='collection_items_retrieve'),
|
||||
# path('collection_items/<int:pk>/delete/', views.CollectionDestroyView.as_view(),
|
||||
# name='collection_items_destroy'),
|
||||
# path('collection_items/<int:pk>/update/', views.CollectionItemUpdateView.as_view(),
|
||||
# name='collection_items_update'),
|
||||
|
||||
path('guides/', views.GuideListView.as_view(),
|
||||
name='guides_list'),
|
||||
path('guides/create/', views.GuideCreateView.as_view(),
|
||||
name='guide_create'),
|
||||
path('guides/<int:pk>/', views.GuideRetrieveView.as_view(),
|
||||
name='guide_retrieve'),
|
||||
path('guides/<int:pk>/delete/', views.GuideDestroyView.as_view(),
|
||||
name='guide_destroy'),
|
||||
path('guides/<int:pk>/update/', views.GuideUpdateView.as_view(),
|
||||
name='guide_update'),
|
||||
# path('guides/create/', views.GuideCreateView.as_view(),
|
||||
# name='guide_create'),
|
||||
# path('guides/<int:pk>/', views.GuideRetrieveView.as_view(),
|
||||
# name='guide_retrieve'),
|
||||
# path('guides/<int:pk>/delete/', views.GuideDestroyView.as_view(),
|
||||
# name='guide_destroy'),
|
||||
# path('guides/<int:pk>/update/', views.GuideUpdateView.as_view(),
|
||||
# name='guide_update'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from rest_framework import generics
|
||||
from rest_framework import permissions
|
||||
|
||||
from collection import models
|
||||
from django.conf import settings
|
||||
from collection.serializers import common as serializers
|
||||
|
||||
|
||||
|
|
@ -11,6 +11,10 @@ class CollectionViewMixin(generics.GenericAPIView):
|
|||
model = models.Collection
|
||||
queryset = models.Collection.objects.all()
|
||||
|
||||
def get_country_code(self):
|
||||
"""Get country_code from cookies."""
|
||||
return self.request.COOKIES.get('country_code')
|
||||
|
||||
|
||||
class CollectionItemViewMixin(generics.GenericAPIView):
|
||||
"""Mixin for CollectionItem view"""
|
||||
|
|
@ -32,9 +36,8 @@ class CollectionListView(CollectionViewMixin, generics.ListAPIView):
|
|||
|
||||
def get_queryset(self):
|
||||
"""Override get_queryset method"""
|
||||
country_id = self.request.query_params.get('country_id')
|
||||
return models.Collection.objects.published()\
|
||||
.by_country(country=country_id)
|
||||
.by_country_code(code=self.get_country_code())
|
||||
|
||||
|
||||
class CollectionRetrieveView(CollectionViewMixin, generics.RetrieveAPIView):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user