Added user list url endpoints

This commit is contained in:
keannu125 2023-03-07 20:39:16 +08:00
parent 3205880bde
commit d2a869b685
4 changed files with 21 additions and 4 deletions

View file

@ -143,6 +143,10 @@ DJOSER = {
'SEND_ACTIVATION_EMAIL': True, 'SEND_ACTIVATION_EMAIL': True,
'SEND_CONFIRMATION_EMAIL': True, 'SEND_CONFIRMATION_EMAIL': True,
'ACTIVATION_URL': 'activation/{uid}/{token}', 'ACTIVATION_URL': 'activation/{uid}/{token}',
'PERMISSIONS': {
'user': ['rest_framework.permissions.AllowAny'],
'user_list': ['rest_framework.permissions.AllowAny'],
},
} }
EMAIL_HOST = 'sandbox.smtp.mailtrap.io' EMAIL_HOST = 'sandbox.smtp.mailtrap.io'

View file

@ -29,7 +29,13 @@ class LogSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Product.history.model model = Product.history.model
fields = ('history_id', 'name', 'quantity', fields = ('history_id', 'id', 'name', 'quantity',
'history_date', 'history_user_id') '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') 'history_date', 'history_user_id')
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'email', 'date_joined')

View file

@ -6,6 +6,7 @@ router = routers.DefaultRouter()
router.register(r'products', views.ProductViewSet) router.register(r'products', views.ProductViewSet)
router.register(r'logs', views.LogViewSet) router.register(r'logs', views.LogViewSet)
router.register(r'lowest_stock_product', views.LeastStockProductViewSet) router.register(r'lowest_stock_product', views.LeastStockProductViewSet)
router.register(r'user_list', views.UserListViewSet)
# Wire up our API using automatic URL routing. # Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API. # Additionally, we include login URLs for the browsable API.

View file

@ -1,7 +1,7 @@
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework import viewsets from rest_framework import viewsets
from django.db.models import Min from django.contrib.auth.models import User
from .serializers import ProductSerializer, LogSerializer from .serializers import ProductSerializer, LogSerializer, UserSerializer
from .models import Product from .models import Product
@ -11,6 +11,12 @@ class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all().order_by('-date_added') 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): class LeastStockProductViewSet(viewsets.ModelViewSet):
# permission_classes = [IsAuthenticated] # permission_classes = [IsAuthenticated]
http_method_names = ['get'] http_method_names = ['get']