saving
This commit is contained in:
23
untitled/model.py
Normal file
23
untitled/model.py
Normal file
@@ -0,0 +1,23 @@
|
||||
class Cat:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def to_dict(self):
|
||||
return {"name": self.name}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data):
|
||||
return Cat(data["name"])
|
||||
|
||||
|
||||
class Save:
|
||||
def __init__(self, version, cat: Cat):
|
||||
self.version = version
|
||||
self.cat = cat
|
||||
|
||||
def to_dict(self):
|
||||
return {"version": self.version, "cat": self.cat.to_dict()}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data):
|
||||
return Save(data["version"], Cat.from_dict(data["cat"]))
|
||||
Reference in New Issue
Block a user