aboutsummaryrefslogtreecommitdiffstats
path: root/backend/routes/forms/index.py
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-12-02 13:14:48 +0200
committerGravatar ks129 <[email protected]>2020-12-02 13:14:48 +0200
commita494835ee5b121e25b35889d7bd24ea4614ee2be (patch)
tree1bd5d2b86459bc4ece76ab192b42cbfbc5640067 /backend/routes/forms/index.py
parentUse cls instead self for Question model validators (diff)
Move MongoDB output to Form model and after convert it to dictionary
We need to convert '_id' key to 'id'.
Diffstat (limited to 'backend/routes/forms/index.py')
-rw-r--r--backend/routes/forms/index.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/backend/routes/forms/index.py b/backend/routes/forms/index.py
index 605f184..f1df210 100644
--- a/backend/routes/forms/index.py
+++ b/backend/routes/forms/index.py
@@ -6,6 +6,7 @@ from starlette.requests import Request
from starlette.responses import JSONResponse
from backend.route import Route
+from backend.models import Form
class FormsList(Route):
@@ -22,7 +23,10 @@ class FormsList(Route):
cursor = request.state.db.forms.find()
for form in await cursor.to_list(None):
- forms.append(form)
+ forms.append(Form(**form)) # For converting _id to id
+
+ # Covert them back to dictionaries
+ forms = [form.dict() for form in forms]
return JSONResponse(
forms