text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
flight/layout.html using that same HTML layout.
4,672.03
4.06
And inside the body of the page, let's just
4,676.09
3.23
say something like in big we'll say flight ID.
4,679.32
5.55
And then, maybe an unordered list where I can say something like the origin
4,684.87
4.05
is flight.origin.
4,688.92
2.43
The destination is flight.destination.
4,691.35
4.46
And the duration is flight.duration.
4,695.81
5.88
So now, I have a page that displays flight information
4,701.69
2.88
about any particular flight.
4,704.57
1.86
And if I go ahead and load not /flights in my web browser, but /flights/one,
4,706.43
5.1
for example.
4,711.53
0.692
Well, now I have information about flight number one.
4,712.222
2.208
And /flight/two gets me information about flight number two.
4,714.43
3.61
Querying for that particular flight, then printing out
4,718.04
2.4
its origin, destination, and duration.
4,720.44
3.04
Now, there is some error checking that we probably should do here.
4,723.48
2.75
If I try and access a flight that doesn't exist,
4,726.23
2
something like flight 28, for example.
4,728.23
2.54
I'm going to get some sort of error that does not exist error.
4,730.77
2.78
Flight matching query does not exist.
4,733.55
2.04
I might like to control what happens in that situation a little better.
4,735.59
3.283
So you might imagine adding some additional error checking
4,738.873
2.417
to handle those cases as well.
4,741.29
1.5
But we'll leave it at this just for now.
4,742.79
2.52
But now, let's go ahead and add the ability,
4,745.31
2.49
not only to have flights that have airports associated with them,
4,747.8
3.24
but let's also add passengers to our flights
4,751.04
2.61
as well to be able to represent passengers that might actually
4,753.65
3.15
be on these flights, too.
4,756.8
2.06
So go ahead and go back into models.py.
4,758.86
3.83
And in models.py, in addition to an airport class and a flight class,
4,762.69
4.43
let me create a new class called passenger.
4,767.12
4.23
Also going to be a model.
4,771.35
1.62
And what properties does a passenger have?
4,772.97
2.22
Well, a passenger has a first name, which
4,775.19
1.92
we'll go ahead and make a models.CharField whose max length
4,777.11
5.34
we'll put at 64.
4,782.45
2.16
And the last name.
4,784.61
2.82
Max length equals 64.
4,787.43
1.95
And passengers also, as we described before,
4,789.38
2.91
they have a many to many relationship with flights.
4,792.29
3.435
That a flight could have multiple passengers,
4,795.725
1.875
a passenger could be on multiple flights,
4,797.6
1.98
and ultimately, we need an additional table to keep track of this.
4,799.58
2.91
But we can think a little bit more abstractly here in Django
4,802.49
2.82
and just say that every passenger has flights associated with them, which are
4,805.31
4.62
a models.manytomanyfield with flight.
4,809.93
4.65
So every passenger could be associated with many flights.
4,814.58
3.64
We'll say blank equals true to allow the possibility that a passenger has
4,818.22
4.07
no flights.
4,822.29
0.6
Maybe if they're not registered for any flights at all.
4,822.89
3.25
And we'll also give this a related name of passengers,
4,826.14
4.01
meaning if I have a passenger, I can use the flights attribute
4,830.15
3.81
to access all of their flights.
4,833.96
1.68
And likewise, if I have a flight, I can use this passenger's related name
4,835.64
4.23
to access all of the passengers who are on that flight.
4,839.87
3.06
And we'll see how that'll be useful in a moment, too.
4,842.93
2.73
The string representation of a passenger will just
4,845.66
3.09
go ahead and be their first name space their last name,
4,848.75
4.05
which feels like a reasonable way of representing a particular passenger.
4,852.8
3.81
And now, I need to apply these changes.
4,856.61
2.31
I need to say, python manage.py.
4,858.92
2.16
Make migrations because I've made new changes to my model.
4,861.08
3.36
I've created a model passenger, in particular.
4,864.44
2.7
And now, if I do python manage.py migrate,
4,867.14
2.91
now I've applied those changes to my actual database.
4,870.05
3.75
And if I go into admin.py, so we'll go into admin.py,
4,873.8
4.86
and register not only flight and airport but passenger,
4,878.66
4.8
admin.site.register passenger, then now via the admin interface,
4,883.46
4.56
I can manipulate passengers as well.
4,888.02
2.25
I can say python manage.py run server to run my web server.
4,890.27
5.28
Go to my web servers admin view by going to /admin.
4,895.55
4.26
Go down to passengers, and let's go ahead and add a passenger.
4,899.81
4.43
Where I can say, all right, first name Harry,
4,904.24
2.08
last name Potter, and we'll go ahead and put him on flight 1 and flight 3,
4,906.32
5.11
maybe.
4,911.43
0.5
He's on two different flights, for example.
4,911.93
1.88
And you can hold down command or control to be able to select multiple flights.
4,913.81
3.55
And we'll go ahead and save that.
4,917.36
1.5
Harry Potter has been added successfully.
4,918.86
1.86
And let's add a couple of other passengers.
4,920.72
1.792
We'll add Ron Weasley.
4,922.512
2.018
And we'll add another.
4,924.53
1.08
We'll add Hermione Granger.
4,925.61
2.7
And we'll add Ginny Weasley as well.
4,928.31
3.17
So we've added a number of different passengers
4,931.48
1.96
that now all exist in Django's admin interface.
4,933.44
2.94
And now, what I'd like to do is on the flight page,
4,936.38
2.52
display information about which passengers
4,938.9
2.52
happened to be on any given flight.
4,941.42
2.37
So the way I might do that is by going into views.py.
4,943.79
5.46
And on the flight page, in addition to giving access to the flight,
4,949.25
3.99
let me also give it access to passengers.
4,953.24
2.49
So passengers this template is going to get access to.
4,955.73
3.28
And we get passengers by saying flight.passengers.all.
4,959.01
4.66
And the reason we can do this is, again, because passengers
4,963.67
3.07
is that related name.
4,966.74
1.29
It is our way of taking a flight and getting all of the passengers that
4,968.03
4.02
happened to be on that flight.
4,972.05
2.7
And so now, inside of flight.html I can add something like,
4,974.75
6.48