allow to work like in django admin which also tries to call the given methon on the object itself

try to call the given serializer method on the serializer itself and on the model in that order
This commit is contained in:
kakulukia 2014-10-13 16:09:45 +02:00
parent 4b4f1bfd4a
commit 553cf5540e

View File

@ -1047,5 +1047,10 @@ class SerializerMethodField(Field):
super(SerializerMethodField, self).__init__(*args, **kwargs)
def field_to_native(self, obj, field_name):
value = getattr(self.parent, self.method_name)(obj)
if hasattr(self.parent, self.method_name):
method = getattr(self.parent, self.method_name)
value = method(obj)
else:
method = getattr(obj, self.method_name)
value = method()
return self.to_native(value)