mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Fix initial data on serializers to reflect writable fields
This commit is contained in:
parent
02844a1507
commit
3e878a3207
|
@ -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()
|
||||||
|
|
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user