diff options
author | Santo Cariotti <dcariotti24@gmail.com> | 2020-07-07 10:09:04 +0200 |
---|---|---|
committer | Santo Cariotti <dcariotti24@gmail.com> | 2020-07-07 13:06:56 +0200 |
commit | 9fc2b563473afa62230cc01f7b78703a8cb8a4d2 (patch) | |
tree | 9870e0c50c164fb9c4d8380d222d6a933ed133ea | |
parent | 051d022004d91cea75630cccbea43a2b652b5f4e (diff) |
fix: extend model for json field
You can make a call with `dict` as member of the list for `extend_model_for`
-rw-r--r-- | frest/utils.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/frest/utils.py b/frest/utils.py index ef673a7..e145b32 100644 --- a/frest/utils.py +++ b/frest/utils.py @@ -33,12 +33,18 @@ def model_serialize(obj, params="", extend_model_for=[]): for v in value: for i in extend_model_for: if isinstance(v, i): - _l.append(v.as_json()) + if hasattr(v, 'as_json'): + _l.append(v.as_json()) + else: + _l.append(v) fields[key] = _l else: for i in extend_model_for: if isinstance(value, i): - fields[key] = value.as_json() + if hasattr(value, 'as_json'): + fields[key] = value.as_json() + else: + fields[key] = value return fields |