Пример #1
0
class UserList(APIView):
    """UserList cbv classdoc"""
    @swagger_auto_schema(query_serializer=UserListQuerySerializer,
                         responses={200: UserSerializerrr(many=True)})
    def get(self, request):
        queryset = User.objects.all()
        serializer = UserSerializerrr(queryset, many=True)
        return Response(serializer.data)

    @swagger_auto_schema(
        operation_description="apiview post description override",
        request_body=openapi.Schema(
            type=openapi.TYPE_OBJECT,
            required=['username'],
            properties={'username': openapi.Schema(type=openapi.TYPE_STRING)},
        ))
    def post(self, request):
        serializer = UserSerializerrr(request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)

    @swagger_auto_schema(request_body=no_body,
                         operation_id="users_dummy",
                         operation_description="dummy operation")
    def patch(self, request):
        pass
Пример #2
0
def user_detail(request, pk):
    """user_detail fbv docstring"""
    user = get_object_or_404(User.objects, pk=pk)
    serializer = UserSerializerrr(user)
    return Response(serializer.data)
Пример #3
0
 def post(self, request):
     serializer = UserSerializerrr(request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data, status=status.HTTP_201_CREATED)
Пример #4
0
 def get(self, request):
     queryset = User.objects.all()
     serializer = UserSerializerrr(queryset, many=True)
     return Response(serializer.data)