diff --git a/apps/collection/models.py b/apps/collection/models.py index f57e7c86..6b5d4146 100644 --- a/apps/collection/models.py +++ b/apps/collection/models.py @@ -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""" diff --git a/apps/collection/urls/common.py b/apps/collection/urls/common.py index 8ae1e92f..a1d98efc 100644 --- a/apps/collection/urls/common.py +++ b/apps/collection/urls/common.py @@ -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('/', views.CollectionRetrieveView.as_view(), - name='collection_retrieve'), - path('/delete/', views.CollectionDestroyView.as_view(), - name='collection_destroy'), - path('/update/', views.CollectionUpdateView.as_view(), - name='collection_update'), + # path('create/', views.CollectionCreateView.as_view(), + # name='collection_create'), + # path('/', views.CollectionRetrieveView.as_view(), + # name='collection_retrieve'), + # path('/delete/', views.CollectionDestroyView.as_view(), + # name='collection_destroy'), + # path('/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//', views.CollectionItemRetrieveView.as_view(), - name='collection_items_retrieve'), - path('collection_items//delete/', views.CollectionDestroyView.as_view(), - name='collection_items_destroy'), - path('collection_items//update/', views.CollectionItemUpdateView.as_view(), - name='collection_items_update'), + # path('collection_items/create/', views.CollectionItemCreateView.as_view(), + # name='collection_items_create'), + # path('collection_items//', views.CollectionItemRetrieveView.as_view(), + # name='collection_items_retrieve'), + # path('collection_items//delete/', views.CollectionDestroyView.as_view(), + # name='collection_items_destroy'), + # path('collection_items//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//', views.GuideRetrieveView.as_view(), - name='guide_retrieve'), - path('guides//delete/', views.GuideDestroyView.as_view(), - name='guide_destroy'), - path('guides//update/', views.GuideUpdateView.as_view(), - name='guide_update'), + # path('guides/create/', views.GuideCreateView.as_view(), + # name='guide_create'), + # path('guides//', views.GuideRetrieveView.as_view(), + # name='guide_retrieve'), + # path('guides//delete/', views.GuideDestroyView.as_view(), + # name='guide_destroy'), + # path('guides//update/', views.GuideUpdateView.as_view(), + # name='guide_update'), ] diff --git a/apps/collection/views/common.py b/apps/collection/views/common.py index 7581974e..eb288daf 100644 --- a/apps/collection/views/common.py +++ b/apps/collection/views/common.py @@ -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):