diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 258c0f6a5..2f475d6ea 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -114,10 +114,6 @@ def strip_multiple_choice_msg(help_text): return help_text.replace(multiple_choice_msg, '') -class IgnoreFieldException(Exception): - pass - - class Field(object): read_only = True creation_counter = 0 @@ -329,7 +325,7 @@ class WritableField(Field): def field_to_native(self, obj, field_name): if self.write_only: - raise IgnoreFieldException() + return None return super(WritableField, self).field_to_native(obj, field_name) def field_from_native(self, data, files, field_name, into): diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 414a769fa..536b040bc 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -346,14 +346,12 @@ class BaseSerializer(WritableField): continue field.initialize(parent=self, field_name=field_name) key = self.get_field_key(field_name) - try: - value = field.field_to_native(obj, field_name) - except IgnoreFieldException: - continue + value = field.field_to_native(obj, field_name) method = getattr(self, 'transform_%s' % field_name, None) if callable(method): value = method(obj, value) - ret[key] = value + if not getattr(field, 'write_only', False): + ret[key] = value ret.fields[key] = self.augment_field(field, field_name, key, value) return ret @@ -389,7 +387,7 @@ class BaseSerializer(WritableField): across relationships. """ if self.write_only: - raise IgnoreFieldException() + return None if self.source == '*': return self.to_native(obj)