From a9c83d7c2ff1f585ae368aaf879aaf21d510f2ea Mon Sep 17 00:00:00 2001 From: Keiran Price Date: Mon, 22 Jul 2019 08:40:06 +0100 Subject: [PATCH] #2: Add docstring to method --- common/models/db_models.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/models/db_models.py b/common/models/db_models.py index 68619bbc..ea49eddf 100644 --- a/common/models/db_models.py +++ b/common/models/db_models.py @@ -22,6 +22,13 @@ def to_dict(self): return dictionary def to_nested_dict(self, included_relations): + """ + Given related models return a nested dictionary with the child or parent rows nested. + + + :param included_relations: string/list/dict - The related models to include. + :return: A nested dictionary with the included models + """ dictionary = {} for column in self.__table__.columns: dictionary[column.name] = str(getattr(self, column.name)) @@ -30,7 +37,7 @@ def to_nested_dict(self, included_relations): if attr in included_relations: relation = getattr(self, attr) if isinstance(relation, EntityHelper): - dictionary[attr + "_ID"] = relation.to_dict() # if this was .to_nested_dict() it will make dictionaries all the way down + dictionary[attr + "_ID"] = relation.to_dict() elif isinstance(relation, InstrumentedList): # Instrumented list is when the inclusion is a child dictionary[attr + "_ID"] = [] for entity in getattr(self, attr):