Python for Entrepreneurs Transcripts
Chapter: Accessing databases from Python: SQLAlchemy ORM
Lecture: Demo: Web form for creating albums and tracks
Login or purchase this course to watch this video and the rest of the course contents.
0:01 It's time to actually insert some data into our web application. Now, you can see I've added right here an admin_controller,
0:07 it has this standard GET / POST / Redirect pattern for editing data. And we've done this before. We did this in the advanced web section.
0:15 Part two of web development. Remember, we just changed stuff in memory We just printed out something, we didn't actually put something in the database,
0:22 because we didn't have SQLAlchemy or any data access technology that we had talked about. But we're going to follow the same pattern
0:29 GET - it's gonna show the form, POST is going handle it and you can see I've got a "todo" down here and we're going to insert some data,
0:36 We'll insert an album and a bunch of tracks that go with it and we're gonna log the fact tht that was done and just a printout,
0:42 Not really logging, we'll get to that later. And we can look at this new_album.pt Alright, a really simple form here, I've done a little bit of work
0:50 to make it look prettier, so for example I've added some Bootstrap here, some Bootstrap stuff over here, so it's gonna look a little bit nicer
0:59 but we basically have the things you need to create an album. We've got title here, price, album image and URL and
1:05 then, we're not gonna go all-in and create a huge backend for managing albums and tracks and reordering them and so on.
1:13 What we're gonna do is we're just gonna take a bunch of track titles, and we're gonna use that to sort of build a some kind of data relationship
1:21 and in the real life, you could of course use this technique to go on and extend what we're doing to let you manage and reorder tracks
1:27 or whatever your equivalent of nested related items are. OK, so we're gonna take this, we also have down here
1:37 a newalbumviewmodel, but that just basically will transfer that stuff to and from the form and then also has this cool property that I added to it
1:47 that given "new line separated", so one per line, text that represents the track titles, it will turn that into
1:55 a tightened-up list of track titles and we're going to use that to create the tracks, like I said in the real one, we'd wanna have
2:03 the length of the track, then various things, maybe audio link to an mp3 that would let us preview it and so on, but this is just gonna be a
2:11 a simple little trick for us to get started