Created
March 10, 2020 19:54
-
-
Save kolygri/9cc1e0a5b91c2de6242f04abeffbb3d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_dict_simple(d): | |
"""Returns the model properties as a dict without None values.""" | |
clean = {} | |
for k, v in list(six.iteritems(d)): | |
if isinstance(v, list): | |
clean[k] = list(map(lambda x: to_dict_simple(x) if isinstance(x, dict) else x, v)) | |
elif isinstance(v, dict): | |
nested = to_dict_simple(v) | |
if len(list(six.iterkeys(nested))) > 0: | |
clean[k] = nested | |
elif v is not None: | |
clean[k] = v | |
return clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment