summaryrefslogtreecommitdiff
path: root/web-server/opendc/models/model.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-07-01 13:33:31 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:47:17 +0200
commitde8f12d74faef5fa3f9e38d1340948cab2d06ea3 (patch)
tree678bf1af3e5fa2334f0df43388d45294785bbf1e /web-server/opendc/models/model.py
parent44236756c4cf689806dc17c6950a2cff3e9227bf (diff)
Manually generate IDs
Diffstat (limited to 'web-server/opendc/models/model.py')
-rw-r--r--web-server/opendc/models/model.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/web-server/opendc/models/model.py b/web-server/opendc/models/model.py
index 1935638f..f42134bf 100644
--- a/web-server/opendc/models/model.py
+++ b/web-server/opendc/models/model.py
@@ -1,3 +1,5 @@
+from uuid import uuid4
+
from opendc.util.database import DB
from opendc.util.exceptions import ClientError
from opendc.util.rest import Response
@@ -23,7 +25,7 @@ class Model:
def get_id(self):
"""Returns the ID of the enclosed object."""
- return self.obj['_id']
+ return str(self.obj['_id'])
def check_exists(self):
"""Raises an error if the enclosed object does not exist."""
@@ -35,12 +37,13 @@ class Model:
self.obj[key] = value
def insert(self):
- """Inserts the enclosed object and updates the internal reference to the newly inserted object."""
- self.obj = DB.insert(self.obj, self.collection_name)
+ """Inserts the enclosed object and generates a UUID for it."""
+ self.obj['_id'] = str(uuid4())
+ DB.insert(self.obj, self.collection_name)
def update(self):
"""Updates the enclosed object and updates the internal reference to the newly inserted object."""
- self.obj = DB.update(self.get_id(), self.obj, self.collection_name)
+ DB.update(self.get_id(), self.obj, self.collection_name)
def delete(self):
"""Deletes the enclosed object in the database."""