From d2a869b685b47ae39827fd27d51faffe1672daba Mon Sep 17 00:00:00 2001 From: keannu125 Date: Tue, 7 Mar 2023 20:39:16 +0800 Subject: [PATCH] Added user list url endpoints --- ivy/config/settings.py | 4 ++++ ivy/products/serializers.py | 10 ++++++++-- ivy/products/urls.py | 1 + ivy/products/views.py | 10 ++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ivy/config/settings.py b/ivy/config/settings.py index 16e9cd3..6787938 100644 --- a/ivy/config/settings.py +++ b/ivy/config/settings.py @@ -143,6 +143,10 @@ DJOSER = { 'SEND_ACTIVATION_EMAIL': True, 'SEND_CONFIRMATION_EMAIL': True, 'ACTIVATION_URL': 'activation/{uid}/{token}', + 'PERMISSIONS': { + 'user': ['rest_framework.permissions.AllowAny'], + 'user_list': ['rest_framework.permissions.AllowAny'], + }, } EMAIL_HOST = 'sandbox.smtp.mailtrap.io' diff --git a/ivy/products/serializers.py b/ivy/products/serializers.py index 7a658f1..453b198 100644 --- a/ivy/products/serializers.py +++ b/ivy/products/serializers.py @@ -29,7 +29,13 @@ class LogSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Product.history.model - fields = ('history_id', 'name', 'quantity', + fields = ('history_id', 'id', 'name', 'quantity', 'history_date', 'history_user_id') - read_only_fields = ('history_id', 'name', 'quantity', + read_only_fields = ('history_id', 'id', 'name', 'quantity', 'history_date', 'history_user_id') + + +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ('id', 'username', 'email', 'date_joined') diff --git a/ivy/products/urls.py b/ivy/products/urls.py index c6f1356..f4c4349 100644 --- a/ivy/products/urls.py +++ b/ivy/products/urls.py @@ -6,6 +6,7 @@ router = routers.DefaultRouter() router.register(r'products', views.ProductViewSet) router.register(r'logs', views.LogViewSet) router.register(r'lowest_stock_product', views.LeastStockProductViewSet) +router.register(r'user_list', views.UserListViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. diff --git a/ivy/products/views.py b/ivy/products/views.py index 35eb93f..9e5c774 100644 --- a/ivy/products/views.py +++ b/ivy/products/views.py @@ -1,7 +1,7 @@ from rest_framework.permissions import IsAuthenticated from rest_framework import viewsets -from django.db.models import Min -from .serializers import ProductSerializer, LogSerializer +from django.contrib.auth.models import User +from .serializers import ProductSerializer, LogSerializer, UserSerializer from .models import Product @@ -11,6 +11,12 @@ class ProductViewSet(viewsets.ModelViewSet): queryset = Product.objects.all().order_by('-date_added') +class UserListViewSet(viewsets.ModelViewSet): + # permission_classes = [IsAuthenticated] + serializer_class = UserSerializer + queryset = User.objects.all() + + class LeastStockProductViewSet(viewsets.ModelViewSet): # permission_classes = [IsAuthenticated] http_method_names = ['get']