fix datetime type does get converted to a string

to_representation will convert the datetime field into a string representation. However the to_representation on the method field will only call its underlying method.
This commit is contained in:
B4rtware 2020-01-08 13:35:38 +01:00 committed by GitHub
parent 23efdb8489
commit e33a6002bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,5 +137,13 @@ class SerializerMutation(ClientIDMutation):
@classmethod
def perform_mutate(cls, serializer, info):
obj = serializer.save()
kwargs = serializer.to_representation(obj)
kwargs = {}
for f, field in serializer.fields.items():
if not field.write_only:
if isinstance(field, serializers.SerializerMethodField):
kwargs[f] = field.to_representation(obj)
else:
kwargs[f] = field.get_attribute(obj)
return cls(errors=None, **kwargs)