We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a06af1b commit 6a642cfCopy full SHA for 6a642cf
fastapi_crudrouter_mongodb/core/models/mongo_model.py
@@ -60,6 +60,8 @@ def convert_to(self, model: BaseModel):
60
if value is not None:
61
if isinstance(value, list):
62
value = self._convert_list(value)
63
+ if isinstance(value, dict):
64
+ value = self._convert_dict(value)
65
new_model[field] = value if type(value) is not ObjectId else str(value)
66
67
return model(**new_model)
@@ -78,6 +80,12 @@ def _convert_list(self, list_to_convert: list):
78
80
new_list.append(sub_object)
79
81
return new_list
82
83
+ def _convert_dict(self, dict_to_convert: dict):
84
+ return {
85
+ field: value if type(value) is not ObjectId else str(value)
86
+ for field, value in dict_to_convert.items()
87
+ if (value is not None)
88
+ }
89
90
def __init__(self, **pydict):
91
super().__init__(**pydict)
0 commit comments