Adding a CMS to Your Flask Web App Transcripts
Chapter: Saving content to the DB
Lecture: Saving a Page

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We've written the sections here so that our redirects now come out of the database. It's time to do the same thing for the pages,
0:09 and you'll see it's really straightforward. Instead of doing that little part, we're just going to have our recession try.
0:18 Do the query finally close the session pattern that we've been using for everything. But now he's gonna be based on pages we gotta import.
0:29 And this one we're trying to find it by the earl So we'll say Page on your URL is the base euro Well, actually, that looks pretty good.
0:40 And it's now going to return a page. Okay, I'm happier, That one. That's pretty straight for Let's just copy this, cause organise that over and over.
0:51 All right, get a page. Should be working. Come down here and say we want all the pages again.
0:57 This is even easier. We can just say that all but it would be nice to have them showing the newest ones first,
1:03 cause you most likely want to work with the ones that you've just created or modified So let's go and do it. Order my page, not created date.
1:12 If we do like that it's us ending. But we want the newer ones will do to sending Nice and changed it to a
1:19 list of pages. And here we'll get get paged by I d. We had to do this weird, funky stuff because of our data structure,
1:29 but in a real database, we don't have to be weird at all. We can say I d is. Hey, JD. All right, well, that's pretty straightforward. And again,
1:38 optional page, not optional dictionary. Go to page. Okay, when I said our data and store it, But not like that time, we're gonna create a page,
1:53 right? Like so and then just set the few things we have to set. Like the title is gonna be the title of that strip contents will be the contents
2:05 that strip in the euro. You're all not strip and the lower case. Okay, that all looks pretty good.
2:18 And let's go ahead and return the page that we created here. And we can say when you create it, you're gonna also get it back.
2:25 We probably won't do anything with it, but just in case, you know, when we hit, save much we're not doing yet.
2:31 We had saved it's going to set things like the created date as well as the idea is the one. I guess we also need tohave the creating user.
2:44 And that's to say that these are all strings. We don't set the creating user. We already saw that crashes. Next,
2:55 we gotta add this to the session and then commit the session over to the database All right, that's probably the tricky is one,
3:05 but I think that we're good. Let's go down to our update page and again, we got to get this from a new session.
3:13 We can't call this function, even though it would give it back to us.
3:16 So let's do you copy this really similar that we're gonna create this session and get the page back, worried by page and filter by what we got.
3:35 I d think we're passing in the I D. So it's use that that's the most likely to work, or it's not gonna change ever.
3:44 And we'll do a little test like so I don't need any of this. We're no longer passing in the create user. That's just whoever originally created it.
3:55 There's not, like a last updated by or something so we don't need that. We're sending all the things it came from the database.
4:01 We're off to add it and yeah, that's that's it. We can say this is going to return a page. It doesn't need to be optional,
4:09 cause at this point, it's definitely here. And if it's not gonna be, there's a rash is an exception.
4:16 All right, well, it looks like we've updated our CMS service to now work with sequel alchemy and read and write those pages from the database.

Talk Python's Mastodon Michael Kennedy's Mastodon