mirror of
https://github.com/lemeow125/Ivy-Backend.git
synced 2025-06-28 16:45:44 +08:00
Polished code
This commit is contained in:
parent
fa684fb195
commit
4f9d2eab6d
5 changed files with 15 additions and 21 deletions
|
@ -4,11 +4,11 @@ from . import views
|
|||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'products', views.ProductViewSet)
|
||||
router.register(r'logs', views.LogViewSet)
|
||||
router.register(r'lowest_stock_product', views.LeastStockProductViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('logs/', views.LogViewSet.as_view()),
|
||||
path('lowest_stock_product/', views.LeastStockProductViewSet.as_view())
|
||||
]
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import viewsets, generics
|
||||
from .serializers import ProductSerializer, LogSerializer
|
||||
from .models import Product
|
||||
|
||||
|
||||
class ProductViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ProductSerializer
|
||||
queryset = Product.objects.all().order_by('-date_added')
|
||||
|
||||
|
||||
class LeastStockProductViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
http_method_names = ['get']
|
||||
class LeastStockProductViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = ProductSerializer
|
||||
queryset = Product.objects.all().order_by('quantity')
|
||||
|
||||
|
@ -20,8 +19,7 @@ class LeastStockProductViewSet(viewsets.ModelViewSet):
|
|||
return super().get_queryset()[:1]
|
||||
|
||||
|
||||
class LogViewSet(viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
http_method_names = ['get']
|
||||
class LogViewSet(generics.ListAPIView):
|
||||
# permission_classes = [IsAuthenticated]
|
||||
serializer_class = LogSerializer
|
||||
queryset = Product.history.all().order_by('-history_date')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue