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.
0:04 Now, you can see I've added right here an admin_controller,
0:06 it has this standard GET / POST / Redirect pattern
0:09 for editing data. And we've done this before. We did this in the advanced web section.
0:14 Part two of web development. Remember, we just changed stuff in memory
0:18 We just printed out something, we didn't actually put something in the database,
0:21 because we didn't have SQLAlchemy or any data access technology
0:24 that we had talked about.
0:26 But we're going to follow the same pattern
0:28 GET - it's gonna show the form, POST is going handle it and you can see
0:31 I've got a "todo" down here and we're going to insert some data,
0:35 We'll insert an album and a bunch of tracks that go with it
0:38 and we're gonna log the fact tht that was done and just a printout,
0:41 Not really logging, we'll get to that later.
0:44 And we can look at this
0:46 Alright, a really simple form here, I've done a little bit of work
0:49 to make it look prettier, so for example
0:51 I've added some Bootstrap here, some Bootstrap stuff over here,
0:56 so it's gonna look a little bit nicer
0:58 but we basically have the things you need to create an album.
1:01 We've got title here, price, album image and URL and
1:04 then, we're not gonna go all-in and create a huge backend
1:08 for managing albums and tracks and reordering them and so on.
1:12 What we're gonna do is we're just gonna take a bunch of track titles,
1:14 and we're gonna use that to sort of build a some kind of data relationship
1:20 and in the real life, you could of course use this technique to go on
1:23 and extend what we're doing to let you manage and reorder tracks
1:26 or whatever your equivalent of nested related items are.
1:33 OK, so we're gonna take this, we also have down here
1:36 a newalbumviewmodel, but that just basically will transfer that stuff
1:40 to and from the form and then also has this cool property that I added to it
1:46 that given "new line separated", so one per line,
1:51 text that represents the track titles, it will turn that into
1:54 a tightened-up list of track titles and we're going to use that
1:59 to create the tracks, like I said in the real one, we'd wanna have
2:02 the length of the track, then various things, maybe audio link to an mp3
2:07 that would let us preview it and so on, but this is just gonna be a
2:10 a simple little trick for us to get started