2022-10-25 23:29:13 +03:00
|
|
|
from django.contrib.auth import get_user_model
|
2022-10-26 23:22:04 +03:00
|
|
|
from rest_framework import generics, status
|
2022-10-25 23:29:13 +03:00
|
|
|
from rest_framework.decorators import action
|
|
|
|
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin, UpdateModelMixin
|
2022-10-26 23:22:04 +03:00
|
|
|
from rest_framework.permissions import AllowAny
|
2022-10-25 23:29:13 +03:00
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.viewsets import GenericViewSet
|
|
|
|
|
2022-10-26 23:22:04 +03:00
|
|
|
from .serializers import RegisterSerializer, UserSerializer
|
2022-10-25 23:29:13 +03:00
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
|
|
|
|
|
|
class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericViewSet):
|
|
|
|
serializer_class = UserSerializer
|
|
|
|
queryset = User.objects.all()
|
|
|
|
lookup_field = "username"
|
|
|
|
|
|
|
|
def get_queryset(self, *args, **kwargs):
|
|
|
|
return self.queryset.filter(id=self.request.user.id)
|
|
|
|
|
|
|
|
@action(detail=False)
|
|
|
|
def me(self, request):
|
|
|
|
serializer = UserSerializer(request.user, context={"request": request})
|
|
|
|
return Response(status=status.HTTP_200_OK, data=serializer.data)
|
2022-10-26 23:22:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
class RegisterView(generics.CreateAPIView):
|
|
|
|
queryset = User.objects.all()
|
|
|
|
permission_classes = (AllowAny,)
|
|
|
|
serializer_class = RegisterSerializer
|