Fix initial data on serializers to reflect writable fields

This commit is contained in:
Tom Christie 2014-11-07 15:38:27 +00:00
parent 02844a1507
commit 3e878a3207
2 changed files with 2 additions and 6 deletions

View File

@ -581,12 +581,7 @@ class BrowsableAPIRenderer(BaseRenderer):
# View has a serializer defined and parser class has a # View has a serializer defined and parser class has a
# corresponding renderer that can be used to render the data. # corresponding renderer that can be used to render the data.
# Get a read-only version of the serializer
serializer = view.get_serializer(instance=instance) serializer = view.get_serializer(instance=instance)
if instance is None:
for name, field in serializer.fields.items():
if getattr(field, 'read_only', None):
del serializer.fields[name]
# Render the raw data content # Render the raw data content
renderer = renderer_class() renderer = renderer_class()

View File

@ -234,12 +234,13 @@ class Serializer(BaseSerializer):
(field_name, field.get_value(self._initial_data)) (field_name, field.get_value(self._initial_data))
for field_name, field in self.fields.items() for field_name, field in self.fields.items()
if field.get_value(self._initial_data) is not empty if field.get_value(self._initial_data) is not empty
and not field.read_only
], serializer=self) ], serializer=self)
return ReturnDict([ return ReturnDict([
(field.field_name, field.get_initial()) (field.field_name, field.get_initial())
for field in self.fields.values() for field in self.fields.values()
if not field.write_only if not field.read_only
], serializer=self) ], serializer=self)
def get_value(self, dictionary): def get_value(self, dictionary):