Adding a CMS to Your Flask Web App Transcripts
Chapter: Saving content to the DB
Lecture: Using the new Redirect class

Login or purchase this course to watch this video and the rest of the course contents.
0:00 remember I told you that we're gonna have to pay for this little change right here We should have just created a redirect class way back.
0:07 Let me rephrase that. I should have created a redirect class instead of a dictionary But no hindsight is 2020. So let's go fix us up.
0:15 You'll see because of the type. Hence it's actually pretty easy and because of you models. So let's go down to our view models here,
0:23 go to the CMS, see if any errors show up. You see them because we specify that this returns a reader at class and we know
0:34 what that is. My charm knows it doesn't have a get. What does it have it just has while it has the oral directly?
0:42 And that's what that crash you saw in the last video was all about? Was that Let's just go quickly through the other view models here about a reader X
0:50 and see what else is going on. All right, so redirect, get name becomes better. Just name and get Euro is now just euro and you guessed it for euro.
1:04 Well, it's short. You're well, I think that might actually do it Let's go. Give it a shot. Refresh this notice.
1:19 We re started the website. The stuff we just typed in It didn't go away It's still there. And let's test this.
1:26 Oh, yeah, Look, it takes us to Python bites and this one should take us to talk by phone training.
1:31 Very, very cool. Let's add one more and let's add a talk by phone line. So the talk Python And there it is. Hey, look at that. It's there now.
1:44 We can't quite edit it. We should be able to pull it up. But when we hit save, remember, we haven't finished that one, so we'll go do that now.
1:51 But this is is good, right? We're making really good progress. But let's just go and write this last update. Redirect and say it's going to return.
2:02 You redirect. This should be okay. We want to check that it exists. So we're gonna given an I d. Get it back now. This was all sorts of weird,
2:14 So let's just fix it now. You would be tempted to say, Here's the redirect, so let's just make changes to that.
2:22 But remember, it just came from a session that was closed. You won't let us read it. Won't let us update. It'll crash. So are trying to save it.
2:31 At least will crash. So we've got to get a new one from a new session. So we're gonna go over here and rob this bid,
2:45 and we're gonna that the redirect to this again? We re name this 12 db Reader Actor. I don't know this team. Redirect.
2:55 We just want to do a quick check. It's probably easier to just in line it like this. There we go. Now we won't be tempted to use it.
3:03 Okay, We get our redirect. And we want to make changes like we want to change the name. So we say name equals name.
3:10 That's cool, right? And reader active dot Short euro equals and short Euro and Euro. People's Euro. That's it? No, we just call commit.
3:24 It's been tracking the fact that we made these changes to it, so it knows it needs to be saved back.
3:28 The database commit. It would redirect close it on the way out. There it goes. That's pretty cool right now.
3:35 If we just rerun this, we should be able to go over here and let's say you know what this is Talk Python to me and this will just call it
3:43 talk. And let's just say question mark Mode is edited. Who knows? Whatever I enter a TV's works what it did.
3:54 How cool is that? We didn't have to change the view model. We didn't have to change the view method, all those things and a new.
4:02 But I guess we had to change the redirect properties from the dot get you know the dictionary access toe the properties.
4:10 But other than look it, it works. Those changes not put in there hands course still goes where you would expect and keeps
4:18 those little changes that we put up there. That is really cool. So we've now completely switched over to using sequel alchemy and
4:28 sequel light as our database back end. Mr. Remind, you remember when we made those changes before and we re started the Web app, they went away.
4:36 Now, of course, they're not going away there saved permanently in the database because that's the job of a database.

Talk Python's Mastodon Michael Kennedy's Mastodon