text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
let's add an H2 called passengers.
4,981.23
2.93
Where here, I'm going to loop for passenger in passengers.
4,984.16
6.41
Go ahead and display that passenger.
4,990.57
4.35
Just print out that passenger inside of a list item.
4,994.92
3.13
And in Django, I can say, if the list is empty,
4,998.05
2.42
let's just have a list item that says, no passengers.
5,000.47
3
Meaning nobody is currently on this flight.
5,003.47
3.9
So now, my web server is still running.
5,007.37
2.25
I can go back to /flights.
5,009.62
2.08
Here are all of the flights.
5,011.7
2.35
And if I go to /flight/one I now see that I'm flight one.
5,014.05
3.76
Harry Potter is a passenger on that flight.
5,017.81
2.35
But if I go to flight two, all right, no passengers are on that flight either.
5,020.16
4.013
And now, it's been a little annoying that I've
5,024.173
1.917
had to do everything by using the URL here to be able to go
5,026.09
3.27
back and forth between pages.
5,029.36
1.65
I could link to those pages if I want to.
5,031.01
2.55
And the way I might do that is, let's on the flight page,
5,033.56
3.48
add a link that goes to the URL index that says something
5,037.04
6.21
like, back to flight list, maybe.
5,043.25
3
So here is now a link that takes me to the index view.
5,046.25
3.15
And likewise, I can go into index.html.
5,049.4
3.36
And for each of these list items, each of these list items
5,052.76
3.51
is really going to be a link that links to it's a url to a particular flight.
5,056.27
7.5
And the flight route takes as a parameter a flight ID.
5,063.77
3.87
And so inside this url a substitution here.
5,067.64
2.88
I can specify use flight.id as the ID of the flight
5,070.52
4.74
that I would like to use here.
5,075.26
2.59
And so now, I've put every single flight inside
5,077.85
2.9
of a link that takes me to the flight route.
5,080.75
2.7
But because the flight route requires as an argument the flight ID,
5,083.45
3.27
I can specify the flight ID here.
5,086.72
3.53
And so now, if I go back to /flights, I now see a list of flights where every
5,090.25
4.15
flight is in fact a link that can take me somewhere else.
5,094.4
3.37
And so now, I can click on any one of those links, like New York to Paris,
5,097.77
4.25
and that takes me to the flight page.
5,102.02
1.71
I can click back to flight lists, that takes me back to the flight list.
5,103.73
3
Click on another flight and go to that flight as well.
5,106.73
2.59
So I've now been able to come up with this way of linking
5,109.32
3.5
these pages together by having links in each of the various different pages
5,112.82
3.57
that take me to some other route as well.
5,116.39
4.3
And so now what I might like to do is, in addition
5,120.69
2.09
to displaying all the passengers on any particular flight,
5,122.78
2.73
also give myself the ability to add passengers to a flight
5,125.51
3.24
as well, which feels like a reasonable thing
5,128.75
2.01
that I might want to do inside of this web application.
5,130.76
3.07
And so how can I go about doing that?
5,133.83
2.117
Well, in order to do that, I'm going to need
5,135.947
1.833
some new route that lets me book a flight for a particular passenger.
5,137.78
4.55
And so I'll go ahead and go back to urls.py.
5,142.33
3.28
And inside of urls.py I'll add a new path that will be int flightid/book.
5,145.61
8.82
And int flightid/book is going to let me book
5,154.43
2.25
a flight for this particular flight ID.
5,156.68
3
For flight one or flight two or flight three, or so forth.
5,159.68
3.81
When I do, we'll go ahead and go to the book view, and we'll name that book.
5,163.49
5.07
And so now, I need to implement the book view.
5,168.56
3.673
So how is this view going to work?
5,172.233
1.417
I'm going to define a function called book
5,173.65
3.64
that is going to take as its argument, not only the request,
5,177.29
3.78
but also a flight ID.
5,181.07
1.89
The first thing, as with before, is I want to get the flight ID.
5,182.96
3.15
But remember from before, that there are multiple ways
5,186.11
2.43
that I can request a web page.
5,188.54
2.07
I can request a web page via the get request method,
5,190.61
2.86
which means I would just like to get this page.
5,193.47
2.48
Or I can request the method via post, meaning
5,195.95
2.19
I would like to send data to the page.
5,198.14
2.19
And generally speaking, anytime you want to manipulate the state of something,
5,200.33
4.24
especially manipulating our database, that
5,204.57
2.12
should be inside of a post request.
5,206.69
2.31
I'm submitting some form, some data.
5,209
2.16
And in response to that post submission, you
5,211.16
2.25
should manipulate what's going on inside of the database.
5,213.41
3.69
So we're going to check when this book route is called upon.
5,217.1
3.9
If request method is post, then we want to perform some sort of action.
5,221
5.31
The flight in question is just going to be flight.objects.get.
5,226.31
4.86
Get the flight whose primary key is that flight ID.
5,231.17
4.29
And then, what I'd also like to do is associated with the form.
5,235.46
3.48
When someone submits this form to book a new passenger on the flight,
5,238.94
3.18
they should tell me what the ID is of the passenger.
5,242.12
3.66
What passenger should I book on the flight?
5,245.78
1.972
Because those are the two pieces of information
5,247.752
1.958
you need to know in order to actually book a flight.
5,249.71
2.28
You need the flight and the passenger information.
5,251.99
3.04
So let's assume for now that the information is
5,255.03
2.48
going to be in request.post and then in square brackets passenger.
5,257.51
5.37
What this means is that the data about which passenger
5,262.88
3.06
ID we want to register on this flight is going
5,265.94
3.63
to be passed in via a form with an input field whose name is passenger.
5,269.57
4.59
The name on any particular input field dictates what name we get--
5,274.16
4.24
is received when a route like this book route
5,278.4
2.66
is able to process the request from the user.
5,281.06
3.16
So we'll go ahead and take that information.
5,284.22
1.9
And because by default this might be a string, let's go ahead
5,286.12
3.43
and convert it into an integer just to make sure
5,289.55
2.4
we're dealing with an integer.
5,291.95
1.65
And let me say that the passenger in question
5,293.6
2.61
is going to be passenger.objects.get pk equals this whole thing.
5,296.21
7.89
So now what I've done is, if the request method
5,304.1
2.73
is post, meaning someone submitted this form via the post request method,
5,306.83
4.05