Added field is_publish to model Collection, updated endpoint to get collection list
This commit is contained in:
parent
ecb6349696
commit
57e7219276
18
apps/collection/migrations/0002_collection_is_publish.py
Normal file
18
apps/collection/migrations/0002_collection_is_publish.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2019-08-21 13:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('collection', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='collection',
|
||||
name='is_publish',
|
||||
field=models.BooleanField(default=False, verbose_name='Publish status'),
|
||||
),
|
||||
]
|
||||
|
|
@ -32,9 +32,15 @@ class CollectionQuerySet(models.QuerySet):
|
|||
"""Filter collection by country id."""
|
||||
return self.filter(country=country_id)
|
||||
|
||||
def published(self):
|
||||
"""Returned only published collection"""
|
||||
return self.filter(is_publish=True)
|
||||
|
||||
|
||||
class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin):
|
||||
"""Collection model."""
|
||||
is_publish = models.BooleanField(
|
||||
default=False, verbose_name=_('Publish status'))
|
||||
filters = JSONField(
|
||||
_('filters'), null=True, blank=True,
|
||||
default=None, help_text='{"key":"value"}')
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
from rest_framework import serializers
|
||||
from collection import models
|
||||
from location.serializers import CountrySerializer
|
||||
|
||||
|
||||
class CollectionSerializer(serializers.ModelSerializer):
|
||||
"""Collection serializer"""
|
||||
country = CountrySerializer()
|
||||
|
||||
class Meta:
|
||||
model = models.Collection
|
||||
fields = [
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
|
|
@ -1,6 +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
|
||||
|
||||
|
||||
|
|
@ -29,6 +30,12 @@ class CollectionListView(CollectionViewMixin, generics.ListAPIView):
|
|||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.CollectionSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
"""Override get_queryset method"""
|
||||
country_id = self.request.query_params.get('country_id')
|
||||
return models.Collection.objects.published()\
|
||||
.filter(country=country_id)
|
||||
|
||||
|
||||
class CollectionRetrieveView(CollectionViewMixin, generics.RetrieveAPIView):
|
||||
"""Retrieve Collection view"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user