You can use the following method which is inspired by the answer alecxe gave.
def get_model_dict(model, row)
if isinstance(row, model):
columns = [x.name for x in list(model.__table__.columns)]
return {x: getattr(row, x) for x in columns}
else:
raise ValueError(f"The provided row is not of type {model.__table__.name.title()}")
Now all you have to…
Top comments (0)