From 3c1428ff799e4fe19e1eb28ed63a7d54c6180f1d Mon Sep 17 00:00:00 2001 From: Jordan Ephron Date: Thu, 12 Dec 2019 06:09:34 -0800 Subject: [PATCH] Fix NotImplementedError for Field.to_internal_value and Field.to_representation (#6996) --- rest_framework/fields.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 11a2915683..2c45ec6f4f 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -605,8 +605,11 @@ def to_internal_value(self, data): Transform the *incoming* primitive data into a native value. """ raise NotImplementedError( - '{cls}.to_internal_value() must be implemented.'.format( - cls=self.__class__.__name__ + '{cls}.to_internal_value() must be implemented for field ' + '{field_name}. If you do not need to support write operations ' + 'you probably want to subclass `ReadOnlyField` instead.'.format( + cls=self.__class__.__name__, + field_name=self.field_name, ) ) @@ -615,9 +618,7 @@ def to_representation(self, value): Transform the *outgoing* native value into primitive data. """ raise NotImplementedError( - '{cls}.to_representation() must be implemented for field ' - '{field_name}. If you do not need to support write operations ' - 'you probably want to subclass `ReadOnlyField` instead.'.format( + '{cls}.to_representation() must be implemented for field {field_name}.'.format( cls=self.__class__.__name__, field_name=self.field_name, )