order products

This commit is contained in:
2025-07-07 13:54:09 +03:30
parent 3035b0c84a
commit bafd1fbbcb
2 changed files with 29 additions and 1 deletions

View File

@@ -95,7 +95,7 @@ class UserRelationViewSet(viewsets.ModelViewSet):
serializer_class = UserRelationSerializer
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date'))
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa
page = self.paginate_queryset(queryset)
if page is not None:

View File

@@ -67,6 +67,34 @@ class ProductViewSet(viewsets.ModelViewSet):
queryset = product_models.Product.objects.all()
serializer_class = product_serializers.ProductSerializer
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
@action(
methods=['get'],
detail=False,
url_path='quotas_statistics',
url_name='quotas_statistics',
name='quotas_statistics'
)
@transaction.atomic
def quotas_statistics_by_product(self, request):
""" quota statistics of each product """
quotas_statistics = []
for product in self.queryset:
quotas_statistics.append(product.quota_information())
return Response(quotas_statistics, status=status.HTTP_200_OK)
@action(
methods=['put'],
detail=True,