Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Saving content to a database
Lecture: A tour of the existing DB layer
0:00 Now it's time for us to get started writing our pages and redirects into the database and using it as a more permanent place in this silly, fake thing that we've been using all along.
0:11 You see, right here we have our Pipi I database that we're going to be using.
0:15 So let's just do a quick tour of the A couple of the existing sequel Alchemy classes and just see everything fits together.
0:22 Then we can jump right in and start writing our page and our redirect classes to put in the database.
0:27 So here's something we've been working a lot with the users table, and it's modeled over here by having a class that derives from our sequel, Alchemy Base.
0:36 Zell sequel Alchemy works great. One of these things, and everything that derives from it automatically gets managed by sequel alchemy.
0:43 I'm using this plural lower case convention for the table names or not, calling it Capital User.
0:49 But because it contains many things in the database for Collenette users like this. From here on out, it's pretty straightforward.
0:55 We have a auto incriminating i d.
0:58 We have the name email, someone gullible, some or not indexed for things like email if you want to find a user by their email address but some passwords and what not going on here?
1:07 Here's our Boolean is admin. People who have this set to true are allowed to get to our CMS management section.
1:14 If it's not such a true, you don't get there and you can see by default. New users are created as non admissions or sets how it should be.
1:22 So this one's pretty straightforward.
1:23 We're going to build something like this for our page over here may be the most complicated thing we have is our package.
1:30 The package is complicated because it has a bunch of information on it. Here. You gonna like Home Page Docks and package or L.
1:37 But it also has a fairly complicated relationship over here with an interesting default sort option and all sorts of stuff.
1:44 We've got this relationship over to, like the releases of the package and so on, and that's pretty much it of these air, the classes that we're using.
1:54 The other thing you've seen, probably as we've been going around, is a single devi session, and the DB session gets initialized to connect to our sequel Light Database sequel Light is nice because you don't need a database server.
2:06 You don't need to set it up. It's automatically comes with Python.
2:09 You probably wouldn't use it for rial for large applications, but for our simple little example, this is the easiest thing.
2:15 So we just set this up in it, creates all the tables and gets everything set up.
2:19 And then whenever we want to create a session, Duke were right to the database We call this function.
2:24 It has basically this cool little change that it makes to make it easier to work with data after we insert it. And that's about it.
2:31 All we have to do is create another class like this.
2:34 Users we're gonna create a page one or a redirect one and set this up, and then it will be good to go. One other thing to notice.
2:41 There's a lot of places that need to see to know that all these classes are exists.
2:47 So we have this all models thing and we're just going toe every time we create some item that's gonna go into the database that we have to put another entry for it right here so there could be a page one release one.
2:58 Probably some other stuff we do later. We also have Ah, limbic over here. An Olympic is for database migrations.
3:06 As you change your database structure or your classes so they match. We're not gonna talk about that. It's here.
3:12 You can play with it, but it's beyond the scope of what we're interested in.
3:15 We're just going to create something like this and throw it into the mix and start working with pages and redirects in the database.