mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
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:
parent
4b4f1bfd4a
commit
553cf5540e
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user