I want to write using the 'shelve' module, but after entering 3 data, I can't enter anymore and the keys in the file are stored incorrectly ['3', '1', '2']. that's what happens on linux, and it's all good on windows
class BasicModel(ABC):
table = '.db'
def __init__(self):
self.id = None
self.created_date = None
self.updated_date = None
self.isValid = True
def save(self):
if self.isValid:
path = getAbsolutePath(self.table)
with shelve.open(path, writeback=True) as db:
# Shu obj yangi yaratilayotgani
if self.id is None:
self.created_date = datetime.now()
if list(db.keys()):
print(list(db.keys()))
self.id = int(list(db.keys())[-1]) + 1
else:
self.id = '1'
else:
self.updated_date = datetime.now()
db[str(self.id)] = self
else:
raise ValueError("Qiymatlardan biri noto'g'iri")
def delete(self):
with shelve.open(getAbsolutePath(self.table)) as db:
del db[str(self.id)]
def objects(table: str):
with shelve.open(getAbsolutePath(table)) as db:
for obj in db.values():
yield obj
@property
def isValid(self):
return self.__isValid
@isValid.setter
def isValid(self, value):
self.__isValid = value
class Brand(BasicModel):
table = 'Brands'
def __init__(self, name):
super().__init__()
self.name = name