23 lines
863 B
Python
23 lines
863 B
Python
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from django.contrib.auth.models import User
|
|
from playlist.serializers import UserSerializer
|
|
from rest_framework.authentication import SessionAuthentication
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
class UserListView(APIView):
|
|
authentication_classes = [SessionAuthentication]
|
|
permission_classes = [IsAuthenticated]
|
|
def get(self, request):
|
|
users = User.objects.all()
|
|
serializer = UserSerializer(users, many=True)
|
|
return Response(serializer.data)
|
|
|
|
class UserDetailView(APIView):
|
|
authentication_classes = [SessionAuthentication]
|
|
permission_classes = [IsAuthenticated]
|
|
def get(self, request, id):
|
|
user = User.objects.get(pk=id)
|
|
serializer = UserSerializer(user)
|
|
return Response(serializer.data)
|