Adding a CMS to Your Flask Web App Transcripts
Chapter: Saving content to the DB
Lecture: Concept: Inserting data with SQLAlchemy
0:00 Let's quickly review inserting something into the database. One of our CMS objects whenever working with sequel Commie it always creates.
0:09 Always start by creating this thing called a session, or, in the design pattern nomenclature of sequel alchemy,
0:15 a unit of work. We've put that into our DB session, class or module, and then we just call create session.
0:23 It does a couple of extra little things toe make it nicer like not let it expire on creating also specifies the type of what comes back here.
0:30 So we get auto complete for the rest of our editor. Both of those air, really small but super advantageous. Then within a try finally block,
0:38 we're going to create the object we want to insert in this case, a page set the properties about it,
0:43 title, euro contents, cleaning them up as we need Teoh and we go to the session and we say, Add that object and then we committed to the database
0:53 and they are friendly block. No matter how we get out of here, we need to close the connection. So we're gonna say session dot clothes and that's it.
1:00 We've now created one of these pages,