Update serializers.md

This commit is contained in:
linchiwei123 2019-07-05 15:08:43 +08:00 committed by GitHub
parent 976739206c
commit a6f96ac810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -966,6 +966,7 @@ The following class is an example of a generic serializer that can handle coerci
into primitive representations. into primitive representations.
""" """
def to_representation(self, obj): def to_representation(self, obj):
output = {}
for attribute_name in dir(obj): for attribute_name in dir(obj):
attribute = getattr(obj, attribute_name) attribute = getattr(obj, attribute_name)
if attribute_name.startswith('_'): if attribute_name.startswith('_'):
@ -991,6 +992,7 @@ The following class is an example of a generic serializer that can handle coerci
else: else:
# Force anything else to its string representation. # Force anything else to its string representation.
output[attribute_name] = str(attribute) output[attribute_name] = str(attribute)
return outout
--- ---