Skip to content

Commit 1f23ba5

Browse files
committed
add autoload to recordmodel
1 parent b4ba3ef commit 1f23ba5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

open_notebook/domain/base.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,21 @@ def parse_datetime(cls, value):
154154

155155

156156
class RecordModel(BaseModel):
157-
record_id: ClassVar[str] = "open_notebook:default_models"
157+
record_id: ClassVar[str]
158158

159-
@classmethod
160-
def load(cls):
161-
result = repo_query(f"SELECT * FROM {cls.record_id};")
159+
def __init__(self, **kwargs):
160+
super().__init__(**kwargs)
161+
self.load()
162+
163+
def load(self):
164+
result = repo_query(f"SELECT * FROM {self.record_id};")
162165
if result:
163166
result = result[0]
164-
dm = cls(**result)
165-
return dm
166-
return cls()
167+
for key, value in result.items():
168+
if hasattr(self, key):
169+
setattr(self, key, value)
170+
return self
167171

168-
@classmethod
169172
def update(self, data):
170173
repo_update(self.record_id, data)
174+
return self.load()

0 commit comments

Comments
 (0)