add: add new model
This commit is contained in:
@@ -8,5 +8,5 @@ urlpatterns = [
|
|||||||
path('order/list/', order_views.OrderListApiView.as_view()),
|
path('order/list/', order_views.OrderListApiView.as_view()),
|
||||||
path('supplier/create/', supp_views.SupplierCreateApiView.as_view()),
|
path('supplier/create/', supp_views.SupplierCreateApiView.as_view()),
|
||||||
path('supplier/<str:tg_id>/', supp_views.SupplierGetApiView.as_view()),
|
path('supplier/<str:tg_id>/', supp_views.SupplierGetApiView.as_view()),
|
||||||
path('supplier/list/', supp_views.SupplierListApiView.as_view()),
|
path('supplier/', supp_views.SupplierListApiView.as_view()),
|
||||||
]
|
]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from rest_framework import views, permissions
|
from rest_framework import views, permissions, generics
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from core.apps.orders.models import Supplier
|
from core.apps.orders.models import Supplier
|
||||||
@@ -19,19 +19,17 @@ class SupplierCreateApiView(views.APIView):
|
|||||||
return Response({'success': True, 'message': 'created'}, status=200)
|
return Response({'success': True, 'message': 'created'}, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierListApiView(generics.ListAPIView):
|
||||||
|
permission_classes = [permissions.IsAdminUser]
|
||||||
|
queryset = Supplier.objects.all()
|
||||||
|
serializer_class = SupplierListSerializer
|
||||||
|
pagination_class = None
|
||||||
|
|
||||||
|
|
||||||
class SupplierGetApiView(views.APIView):
|
class SupplierGetApiView(views.APIView):
|
||||||
def get(self, request, tg_id):
|
def get(self, request, tg_id):
|
||||||
supp = Supplier.objects.filter(tg_id=tg_id).first()
|
supp = Supplier.objects.filter(tg_id=tg_id).first()
|
||||||
if supp:
|
if supp:
|
||||||
return Response({'success': True}, status=200)
|
return Response({'success': True}, status=200)
|
||||||
else:
|
else:
|
||||||
return Response({"success": False},status=404)
|
return Response({"success": False},status=404)
|
||||||
|
|
||||||
|
|
||||||
class SupplierListApiView(views.APIView):
|
|
||||||
permission_classes = [permissions.IsAdminUser]
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
supp = Supplier.objects.all()
|
|
||||||
serializer = SupplierListSerializer(supp, many=True)
|
|
||||||
return Response(serializer.data, status=200)
|
|
||||||
Reference in New Issue
Block a user