2023-03-05 21:56:48 +08:00
|
|
|
from rest_framework.permissions import IsAuthenticated
|
2023-03-29 14:09:24 +08:00
|
|
|
from rest_framework import viewsets, generics
|
2023-03-07 23:48:52 +08:00
|
|
|
from .serializers import ProductSerializer, LogSerializer
|
2023-03-05 21:56:48 +08:00
|
|
|
from .models import Product
|
|
|
|
|
|
|
|
|
|
|
|
class ProductViewSet(viewsets.ModelViewSet):
|
2023-03-29 14:09:24 +08:00
|
|
|
# permission_classes = [IsAuthenticated]
|
2023-03-05 21:56:48 +08:00
|
|
|
serializer_class = ProductSerializer
|
2023-03-07 19:28:38 +08:00
|
|
|
queryset = Product.objects.all().order_by('-date_added')
|
|
|
|
|
|
|
|
|
2023-03-29 14:09:24 +08:00
|
|
|
class LeastStockProductViewSet(generics.ListAPIView):
|
|
|
|
# permission_classes = [IsAuthenticated]
|
2023-03-07 19:28:38 +08:00
|
|
|
serializer_class = ProductSerializer
|
|
|
|
queryset = Product.objects.all().order_by('quantity')
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return super().get_queryset()[:1]
|
2023-03-07 17:23:39 +08:00
|
|
|
|
|
|
|
|
2023-03-29 14:09:24 +08:00
|
|
|
class LogViewSet(generics.ListAPIView):
|
|
|
|
# permission_classes = [IsAuthenticated]
|
2023-03-07 17:23:39 +08:00
|
|
|
serializer_class = LogSerializer
|
2023-03-07 18:26:00 +08:00
|
|
|
queryset = Product.history.all().order_by('-history_date')
|