Added new field rank to collection
This commit is contained in:
parent
e0a66f300b
commit
450ca4cf52
|
|
@ -80,6 +80,8 @@ class Collection(ProjectBaseMixin, CollectionDateMixin,
|
|||
verbose_name=_('Collection slug'), editable=True, null=True)
|
||||
old_id = models.IntegerField(null=True, blank=True)
|
||||
|
||||
rank = models.IntegerField(null=True, default=None)
|
||||
|
||||
objects = CollectionQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class CollectionBackOfficeSerializer(CollectionBaseSerializer):
|
|||
# 'end',
|
||||
'count_related_objects',
|
||||
'related_object_names',
|
||||
'rank',
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -68,15 +69,15 @@ class CollectionBindObjectSerializer(serializers.Serializer):
|
|||
attrs['collection'] = collection
|
||||
|
||||
if obj_type == self.ESTABLISHMENT:
|
||||
establishment = Establishment.objects.filter(pk=obj_id).\
|
||||
establishment = Establishment.objects.filter(pk=obj_id). \
|
||||
first()
|
||||
if not establishment:
|
||||
raise BindingObjectNotFound()
|
||||
if request.method == 'POST' and collection.establishments.\
|
||||
if request.method == 'POST' and collection.establishments. \
|
||||
filter(pk=establishment.pk).exists():
|
||||
raise ObjectAlreadyAdded()
|
||||
if request.method == 'DELETE' and not collection.\
|
||||
establishments.filter(pk=establishment.pk).\
|
||||
if request.method == 'DELETE' and not collection. \
|
||||
establishments.filter(pk=establishment.pk). \
|
||||
exists():
|
||||
raise RemovedBindingObjectNotFound()
|
||||
attrs['related_object'] = establishment
|
||||
|
|
@ -84,10 +85,10 @@ class CollectionBindObjectSerializer(serializers.Serializer):
|
|||
product = Product.objects.filter(pk=obj_id).first()
|
||||
if not product:
|
||||
raise BindingObjectNotFound()
|
||||
if request.method == 'POST' and collection.products.\
|
||||
if request.method == 'POST' and collection.products. \
|
||||
filter(pk=product.pk).exists():
|
||||
raise ObjectAlreadyAdded()
|
||||
if request.method == 'DELETE' and not collection.products.\
|
||||
if request.method == 'DELETE' and not collection.products. \
|
||||
filter(pk=product.pk).exists():
|
||||
raise RemovedBindingObjectNotFound()
|
||||
attrs['related_object'] = product
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from rest_framework import generics
|
||||
from rest_framework import permissions
|
||||
from rest_framework import viewsets, mixins
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.response import Response
|
||||
|
||||
from collection import models
|
||||
from collection.serializers import back as serializers
|
||||
|
|
@ -49,6 +50,11 @@ class CollectionBackOfficeViewSet(mixins.CreateModelMixin,
|
|||
elif obj_type == self.bind_object_serializer_class.PRODUCT:
|
||||
collection.products.remove(related_object)
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
queryset = self.filter_queryset(self.get_queryset()).order_by('rank', '-start')
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class CollectionBackOfficeView(generics.GenericAPIView):
|
||||
"""ViewS for Collection model."""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user