Support `attribute` parameter on `Function` schema fields.

This commit is contained in:
Fabio Manganiello 2022-08-28 11:55:30 +02:00
parent d890b6cbe8
commit 0e3cabc5f6
Signed by untrusted user: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 3 additions and 1 deletions

View File

@ -22,7 +22,9 @@ class StrippedString(fields.Function): # lgtm [py/missing-call-to-init]
class Function(fields.Function): # lgtm [py/missing-call-to-init]
def _get_attr(self, obj, attr: str):
def _get_attr(self, obj, attr: str, _recursive=True):
if self.attribute and _recursive:
return self._get_attr(obj, self.attribute, False)
if hasattr(obj, attr):
return getattr(obj, attr)
elif hasattr(obj, 'get'):