fix order
This commit is contained in:
1 parent
ae4dbab3cc
commit
4dc6d98abf
3 files changed
+39
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
from apps.shop.models import Product as ProductModel
|
||||
from rest_framework import exceptions
|
||||
from apps.shop.ordering import product_ordering
|
||||
|
||||
|
||||
def retrieve_product(product_id: int, workspace_uuid: str) -> ProductModel:
|
||||
@@ -23,7 +24,7 @@ def list_product(workspace_uuid: str) -> ProductModel:
|
||||
def list_product_by_category(workspace_uuid: str, category_id: int) -> ProductModel:
|
||||
try:
|
||||
product_category_obj = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid, category_id=category_id,
|
||||
view_only=False)
|
||||
view_only=False).order_by(*product_ordering())
|
||||
return product_category_obj
|
||||
except Exception as exp:
|
||||
message = f'Error Fetching List Product by category: {exp}'
|
||||
@@ -33,7 +34,7 @@ def list_product_by_category(workspace_uuid: str, category_id: int) -> ProductMo
|
||||
def list_view_only_product_by_category(workspace_uuid: str, category_id: int) -> ProductModel:
|
||||
try:
|
||||
view_only_product_category_obj = ProductModel.objects.filter(sys_ws__uuid=workspace_uuid, category_id=category_id,
|
||||
view_only=True)
|
||||
view_only=True).order_by(*product_ordering())
|
||||
return view_only_product_category_obj
|
||||
except Exception as exp:
|
||||
message = f'Error Fetching View Only List Product by category: {exp}'
|
||||
@@ -46,4 +47,4 @@ def count_product_in_category(workspace_uuid: str, category_id: int) -> int:
|
||||
return count_product
|
||||
except Exception as exp:
|
||||
message = f'Error Couting Product in category: {exp}'
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
raise exceptions.ValidationError({'error': message})
|
||||
@@ -9,6 +9,7 @@ from apps.shop.selectors import *
|
||||
from rest_framework import generics
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from django.db.models import Count
|
||||
from apps.shop.ordering import category_ordering
|
||||
from utils.tools import inline_serializer
|
||||
from utils import custom_permissions
|
||||
|
||||
@@ -164,7 +165,7 @@ class ProductsCategoryApi(APIView):
|
||||
|
||||
p_cate = ProductCategoryModel.objects.filter(
|
||||
sys_ws__uuid=get_user_workspace_uuid(request),
|
||||
).annotate(product_count=Count('product')).filter(product_count__gte=1)
|
||||
).annotate(product_count=Count('product')).filter(product_count__gte=1).order_by(*category_ordering())
|
||||
output = self.OutputSerializer(p_cate, many=True)
|
||||
|
||||
return Response(data=output.data, status=status.HTTP_200_OK)
|
||||
Reference in new issue
Block a user