From 919c625bbc637aee8e4d0dff4f438604b32a43f7 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Fri, 23 Aug 2019 16:30:28 +0300 Subject: [PATCH] added flag on_top to model Collection, refactored CollectionList view --- .../migrations/0004_collection_on_top.py | 18 ++++++++++++++++++ apps/collection/models.py | 2 ++ apps/collection/serializers/common.py | 3 ++- apps/collection/views/common.py | 3 ++- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 apps/collection/migrations/0004_collection_on_top.py diff --git a/apps/collection/migrations/0004_collection_on_top.py b/apps/collection/migrations/0004_collection_on_top.py new file mode 100644 index 00000000..8e52166f --- /dev/null +++ b/apps/collection/migrations/0004_collection_on_top.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.4 on 2019-08-23 13:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('collection', '0003_auto_20190823_0935'), + ] + + operations = [ + migrations.AddField( + model_name='collection', + name='on_top', + field=models.BooleanField(default=False, verbose_name='Position on top'), + ), + ] diff --git a/apps/collection/models.py b/apps/collection/models.py index a55fd832..e9c226ab 100644 --- a/apps/collection/models.py +++ b/apps/collection/models.py @@ -43,6 +43,8 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, """Collection model.""" is_publish = models.BooleanField( default=False, verbose_name=_('Publish status')) + on_top = models.BooleanField( + default=False, verbose_name=_('Position on top')) filters = JSONField( _('filters'), null=True, blank=True, default=None, help_text='{"key":"value"}') diff --git a/apps/collection/serializers/common.py b/apps/collection/serializers/common.py index c00922ed..44082406 100644 --- a/apps/collection/serializers/common.py +++ b/apps/collection/serializers/common.py @@ -11,7 +11,8 @@ class CollectionSerializer(serializers.ModelSerializer): 'id', 'name', 'block_size', - 'image' + 'image', + 'on_top' ] diff --git a/apps/collection/views/common.py b/apps/collection/views/common.py index 956ecd07..e05fb424 100644 --- a/apps/collection/views/common.py +++ b/apps/collection/views/common.py @@ -33,7 +33,8 @@ class CollectionListView(CollectionViewMixin, generics.ListAPIView): def get_queryset(self): """Override get_queryset method""" return models.Collection.objects.published()\ - .by_country_code(code=self.request.country_code) + .by_country_code(code=self.request.country_code)\ + .order_by('-on_top', '-created') class CollectionRetrieveView(CollectionViewMixin, generics.RetrieveAPIView):