mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
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:
commit
74ac2d2489
|
@ -1045,5 +1045,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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user