I have made a class called Database that I use to manage a connection to a Postgres database via psycopg3. This enables me to do things like:
db = Database(postgres_connection_data)
class_one_instance.insert(insert_data, db)
class_two_instance.insert(insert_data, db)
db.commit()
The exception handling in the insert methods is such that we only get to db.commit() if both inserts have worked, which is exactly what I want.
I am exploring Django as an option in our stack and I would like to replace the implementation of class two's insert() with save() from models.Model. How can I use my Database object with save()?
def insert(self, insert_data, db):
self.save()