text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
I'm first thing flights.objects.get. to get a particular flight,
5,310.88
3.81
get me the flight with that flight ID.
5,314.69
2.55
And then, I'm getting a passenger.
5,317.24
1.77
Which passenger am I getting?
5,319.01
1.5
The one who's pk, their primary key, otherwise known as ID,
5,320.51
3.36
is equal to whatever was submitted via this post form
5,323.87
3.96
with a name of passenger.
5,327.83
1.89
And we haven't yet created that form, but we'll do so in just a moment.
5,329.72
3.97
Now ultimately, we'll want to add some more error checking to this as well,
5,333.69
3.29
like what if someone requests a passenger that doesn't exist,
5,336.98
2.82
or a flight that doesn't exist either.
5,339.8
1.7
So there is definitely some error checking
5,341.5
1.75
that we probably should be doing here.
5,343.25
1.78
But for simplicity, let's just assume for now that we're able to get a flight
5,345.03
4.01
and get a passenger.
5,349.04
1.62
Well, how do we access a passenger's flights?
5,350.66
2.43
I can just say passenger.flights.
5,353.09
3.45
And in order to add a new item to some set like flights,
5,356.54
3.6
I can just say passenger.flights.add flight.
5,360.14
3.992
And this will do the equivalent of adding
5,364.132
1.708
a new row into a table of keeping track that the passengers on that flight.
5,365.84
3.9
But the nice thing about Django's abstractions
5,369.74
2.19
is that I don't have to worry about those underlying details.
5,371.93
2.67
I don't have to worry about what the structures of the tables are.
5,374.6
2.82
I can think at a much higher level and just say take this passenger,
5,377.42
4.44
take their set of flights, and go ahead and add a new flight
5,381.86
3.42
to that set of flights.
5,385.28
2.54
And when all that's said and done, what I probably want to do
5,387.82
3.43
is return some sort of redirect that redirects the user back
5,391.25
4.17
to the flight page.
5,395.42
1.14
So we'll go ahead and return an HTTP response redirect.
5,396.56
4.65
What you URL would I like to take them to?
5,401.21
1.96
Well, I'd like to take them to the flight route.
5,403.17
3.53
And reverse, again, takes the name of a particular view,
5,406.7
3.18
and gets me what the URL is, and we saw that last time.
5,409.88
3.3
And the flight route takes an argument.
5,413.18
1.75
So I need to pass as an argument the flight's ID.
5,414.93
3.688
So I need to provide it to the flight route
5,418.618
1.792
what the flight's ID is, structured it as a tuple,
5,420.41
3.21
and that is going to redirect me back to the flight route
5,423.62
3.6
so that I can see that flight page again.
5,427.22
3.57
And what I need to add up at the top here is from django.http.
5,430.79
4.95
Import HttpResponseRedirect in addition to from django.urls import reverse.
5,435.74
11.63
And so those I'll need to add as well so that I
5,447.37
2.18
can redirect the user back to the flight page
5,449.55
2.67
after they're done submitting the form.
5,452.22
1.68
And reverse takes the name of a particular view,
5,453.9
3.21
as defined in urls.py, something like index or flight or book,
5,457.11
4.11
and gets me what the actual URL path should be.
5,461.22
3.1
And as we talked about last time, that's helpful
5,464.32
2
so that I don't have to hard code URLs into my Django web application.
5,466.32
4.02
I can just reference URLs by their name.
5,470.34
2.28
And if ever I need to change a URL, I can just
5,472.62
2.25
change it in one place in urls.py, and that change
5,474.87
3.72
is going to reflect everywhere else as well.
5,478.59
3.9
So now, the next thing I need to do is actually create this form.
5,482.49
3.89
That what I have so far is just a function
5,486.38
2.23
called book that is waiting for a post request to be made to it.
5,488.61
3.63
And when a post request is made to it, then we're
5,492.24
2.22
going to go ahead and submit this form and go ahead and add the flight
5,494.46
3.39
for this particular passenger.
5,497.85
1.68
But what I'd like to do now is actually add that form.
5,499.53
2.83
So I'll go back into templates, go into flight.html,
5,502.36
4.32
and what I'd like to add here is a form.
5,506.68
2.57
I'll go ahead and label it with an H2 called add passenger.
5,509.25
3.93
And we'll create a form whose action is going to be URL of book.
5,513.18
7.04
So we're going to go to the book route.
5,520.22
1.72
And again, if we recall the book route in urls.py,
5,521.94
2.77
the route with name book, this view, requires as a parameter some flight ID.
5,524.71
5.54
So I need to provide the flight ID as an argument for what flight
5,530.25
3.81
I'm booking the passenger on.
5,534.06
1.86
And it just so happens to be flight.id because this template has
5,535.92
2.97
access to a variable called flight.
5,538.89
2.84
The method of this submission is, again, going to be post.
5,541.73
3.67
And recall from before that whenever I have a form in Django,
5,545.4
2.76
I need to give it the CSRF token just for security to make sure
5,548.16
3.45
that Django knows it's really this application that
5,551.61
2.55
is submitting this form.
5,554.16
1.56
We'll go ahead and add a dropdown list, which you can
5,555.72
2.49
create in HTML using a select field.
5,558.21
3.06
The name of this select field is going to be passenger.
5,561.27
4.14
And the reason for that is inside of views.py, when I get the passenger,
5,565.41
4.56
I'm looking for inside the post data, inside of request.post,
5,569.97
3.6
for a field whose name is passenger.
5,573.57
2.31
And so that is what I would like the name of this dropdown to be.
5,575.88
3.77
And inside of a select dropdown, we have a whole bunch of options.
5,579.65
3.46
Options that we can choose from.
5,583.11
1.57
And there's going to be one option for everyone who
5,584.68
2.72
isn't a passenger on this flight.
5,587.4
3.3
And so how do I get everyone who isn't a passenger on the flight?
5,590.7
3.15
Well, it seems that right now, the flight page only has access
5,593.85
3.3
to actual passengers, and doesn't yet have access to people
5,597.15
3.87
that are not passengers on the flight.
5,601.02
2.4
So it sounds like I need to add some additional context to this template.
5,603.42
3.57
Additional information that we want access to.
5,606.99
2.88
So I'll go ahead and give this flight access to additional information
5,609.87
3.39
that we'll call non-passengers.
5,613.26
2.28
For people that are not on the flight.
5,615.54
2.46
And how do we I non-passengers?
5,618
1.92
Well, just as I could say passenger.objects.filter
5,619.92
3.72