def post(self, request, format=None): serializer = ProfileSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, *args, **kwargs): try: user = self.get_object(pk) user_serializer = ProfileSerializer(instance=user, data=request.data) if user_serializer.is_valid(): user = user_serializer.save() return Response(user_serializer.data, status=status.HTTP_200_OK) else: message = '' for error in user_serializer.errors.values(): message += " " message += error[0] return Response({ 'status': False, 'message': message }, status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response({ 'status': False, 'message': str(e) }, status=status.HTTP_400_BAD_REQUEST)
def post(self, request): """ Creates Profile record """ serializer = ProfileSerializer(data=request.data) if serializer.is_valid(raise_exception=ValueError): serializer.create(validated_data=request.data) return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.error_messages, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): user = get_object_or_404(Profile, pk=pk) serializer = ProfileSerializer(user, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)