def save(entity, _clazz=None):
if _clazz:
if hasattr(entity, 'id'): # usually id is None so this method acs as normal save
_id = entity.id
else:
_id = entity.name
try:
if _id:
found = find(_clazz, _id)
if isinstance(found, list):
for e in found:
delete(e)
else:
if found:
delete(found)
except NoResultFound:
pass
with get_db_session() as se:
se.add(entity)
se.commit()
评论列表
文章目录