Merge branch 'master' of github.com:kakulukia/django-rest-framework

# By kakulukia
# Via kakulukia
* 'master' of github.com:kakulukia/django-rest-framework:
  allow to work like in django admin which also tries to call the given methon on the object itself
  Update fields.py

Conflicts:
	rest_framework/fields.py
This commit is contained in:
Andy Grabow 2014-10-20 11:04:47 +02:00
commit 74ac2d2489

View File

@ -1045,5 +1045,10 @@ class SerializerMethodField(Field):
super(SerializerMethodField, self).__init__(*args, **kwargs) super(SerializerMethodField, self).__init__(*args, **kwargs)
def field_to_native(self, obj, field_name): 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) return self.to_native(value)