yangi api qoshildi
This commit is contained in:
24
core/apps/shared/serializers/dis_product.py
Normal file
24
core/apps/shared/serializers/dis_product.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# rest framework
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
# orders
|
||||||
|
from core.apps.orders.models import DistributedProduct
|
||||||
|
|
||||||
|
|
||||||
|
class DistributedProductListSerializer(serializers.ModelSerializer):
|
||||||
|
product = serializers.SerializerMethodField(method_name='get_product')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = DistributedProduct
|
||||||
|
fields = [
|
||||||
|
'id', 'product', 'quantity', 'employee_name', 'quantity', 'created_at'
|
||||||
|
]
|
||||||
|
ref_name = "DisProductListSerializer"
|
||||||
|
|
||||||
|
def get_product(self, obj):
|
||||||
|
return {
|
||||||
|
"id": obj.product.id,
|
||||||
|
"name": obj.product.name,
|
||||||
|
"price": obj.product.price,
|
||||||
|
}
|
||||||
|
|
||||||
@@ -20,6 +20,8 @@ from core.apps.shared.views import tour_plan as tp_view
|
|||||||
from core.apps.shared.views import factory as factory_view
|
from core.apps.shared.views import factory as factory_view
|
||||||
# shared support view
|
# shared support view
|
||||||
from core.apps.shared.views import support as support_view
|
from core.apps.shared.views import support as support_view
|
||||||
|
# shared dis product
|
||||||
|
from core.apps.shared.views import dis_product as dp_view
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -90,5 +92,10 @@ urlpatterns = [
|
|||||||
path('send/', support_view.SupportCreateApiView.as_view(), name='support-create-api'),
|
path('send/', support_view.SupportCreateApiView.as_view(), name='support-create-api'),
|
||||||
path('list/', support_view.SupportListApiView.as_view(), name='support-list-api'),
|
path('list/', support_view.SupportListApiView.as_view(), name='support-list-api'),
|
||||||
]
|
]
|
||||||
))
|
)),
|
||||||
|
path('distributed_product/', include(
|
||||||
|
[
|
||||||
|
path('list/', dp_view.DistributedProductListApiView.as_view()),
|
||||||
|
]
|
||||||
|
)),
|
||||||
]
|
]
|
||||||
75
core/apps/shared/views/dis_product.py
Normal file
75
core/apps/shared/views/dis_product.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# django
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
# rest framework
|
||||||
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
|
# drf yasg
|
||||||
|
from drf_yasg import openapi
|
||||||
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
|
|
||||||
|
# orders
|
||||||
|
from core.apps.orders.models import DistributedProduct
|
||||||
|
|
||||||
|
# shared
|
||||||
|
from core.apps.shared.utils.response_mixin import ResponseMixin
|
||||||
|
|
||||||
|
# dashboard
|
||||||
|
from core.apps.shared.serializers.dis_product import DistributedProductListSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class DistributedProductListApiView(generics.GenericAPIView, ResponseMixin):
|
||||||
|
serializer_class = DistributedProductListSerializer
|
||||||
|
queryset = DistributedProduct.objects.all()
|
||||||
|
permission_classes = [permissions.IsAdminUser]
|
||||||
|
|
||||||
|
@swagger_auto_schema(
|
||||||
|
manual_parameters=[
|
||||||
|
openapi.Parameter(
|
||||||
|
in_=openapi.IN_QUERY,
|
||||||
|
name="product",
|
||||||
|
description="product name bo'yicha filter",
|
||||||
|
required=False,
|
||||||
|
type=openapi.TYPE_STRING,
|
||||||
|
),
|
||||||
|
openapi.Parameter(
|
||||||
|
in_=openapi.IN_QUERY,
|
||||||
|
name="date",
|
||||||
|
description="date bo'yicha qidirish",
|
||||||
|
required=False,
|
||||||
|
type=openapi.FORMAT_DATE,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def get(self, request):
|
||||||
|
try:
|
||||||
|
product_name = request.query_params.get('product', None)
|
||||||
|
date = request.query_params.get('date', None)
|
||||||
|
|
||||||
|
queryset = self.queryset.filter(user=request.user)
|
||||||
|
|
||||||
|
# filters
|
||||||
|
if product_name is not None:
|
||||||
|
queryset = queryset.filter(product__name__istartswith=product_name)
|
||||||
|
|
||||||
|
if date is not None:
|
||||||
|
queryset = queryset.filter(date=date)
|
||||||
|
|
||||||
|
page = self.paginate_queryset(queryset)
|
||||||
|
if page is not None:
|
||||||
|
serializer = self.serializer_class(page, many=True)
|
||||||
|
return self.success_response(
|
||||||
|
data=self.get_paginated_response(serializer.data).data,
|
||||||
|
message="Malumotlar fetch qilindi",
|
||||||
|
)
|
||||||
|
serializer = self.serializer_class(queryset, many=True)
|
||||||
|
return self.success_response(
|
||||||
|
data=serializer.data,
|
||||||
|
message='Malumotlar fetch qilindi'
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return self.error_response(
|
||||||
|
data=str(e),
|
||||||
|
message='xatolik, iltimos backend dasturchiga murojaat qiling'
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user