I’m using SQLAlchemy in project that is not a web application. It is a server application that loads number of different objects from database and modifies them locally, but don’t want to save those updates to the database each time a commit is issued. I was previously working with Django ORM for some web projects and found it better suited for what I’m trying to achieve. In Django ORM I could .save() each object whenever I wanted without saving other things I may not want to save. I understand why it works like this in SQLAlchemy, but I wonder how I could do this in the Django-like way?
Update:
To make it easier to understand what I’m trying to achieve, I’ll provide you an example.
This is how it works actually:
a = MyModel.query.get(1)
b = MyModel.query.get(1)
a.somefield = 1
b.somefield = 2
# this will save both of changed models
session.commit()
This is how I want it to work:
a = MyModel.query.get(1)
b = MyModel.query.get(1)
a.somefield = 1
b.somefield = 2
a.save()
# I didn't want to save b, changes of b weren't committed
I want to have greater control of what is actually saved. I want to save changes of each object every 5 minute or so.
I use something like:
and then I define my models as:
So, now I can do:
This is what you were planning to achieve ?