Serialization
You might also need a serialization method in the model for getting all values of the table in the format of ex. a dictionary. A serialization method can look like this:
It's good practice to call the serialization method s()
, that way you can also utilize the built-in serialize()
function.
Example
db_model MyModel:
id = db.col(db.int, db.pk)
column1 = db.col(db.str(100))
column2 = db.col(db.float, db.unique, db.nullable)
def _init(self, column1, column2):
self.column1 = column1,
self.column2 = column2
def s(self):
return {
id: self.id,
column1: self.column1,
column2: self.column2
}
Last updated