added flag on_top to model Collection, refactored CollectionList view

This commit is contained in:
Anatoly 2019-08-23 16:30:28 +03:00
parent e2767af57d
commit 919c625bbc
4 changed files with 24 additions and 2 deletions

View File

@ -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'),
),
]

View File

@ -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"}')

View File

@ -11,7 +11,8 @@ class CollectionSerializer(serializers.ModelSerializer):
'id',
'name',
'block_size',
'image'
'image',
'on_top'
]

View File

@ -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):