text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
be references to a particular airport.
3,729.78
2.1
So that's something that's going to need to change in the database.
3,731.88
3.15
And to make that change, I can run something like python manage.py
3,735.03
4.86
migrate to go ahead and apply those changes.
3,739.89
2.58
We've now applied this migration that we just created,
3,742.47
3.09
and our database is now up to date.
3,745.56
3.39
So what can we do?
3,748.95
1.24
Well, now I can go ahead and go back into the shell.
3,750.19
2.96
And I'll just go ahead and import from flights.models import
3,753.15
3.27
star, import everything.
3,756.42
2.23
And I can now create an airport.
3,758.65
1.67
I can say something like JFK equals an airport whose code is JFK
3,760.32
5.94
and whose city is New York, for example.
3,766.26
3.18
And then save that.
3,769.44
1.44
I can create a London one.
3,770.88
1.17
So LHR is an airport whose code is LHR and whose city is London.
3,772.05
5.6
And I can save that.
3,777.65
1.413
You could create more.
3,779.063
0.917
I could say CDG equals an airport whose code is CDG and city is Paris.
3,779.98
6.29
And maybe we'll do one more.
3,786.27
1.4
We'll say NRT is the airport whose code is NRT and whose city is Tokyo,
3,787.67
5.44
for example.
3,793.11
1.09
So I've created and saved four airports that get added to my airport table.
3,794.2
4.28
And now, I can add a flight.
3,798.48
2.25
F equals flight whose origin equals JFK whose destination equals
3,800.73
5.97
London Heathrow and whose duration equals 415 minutes.
3,806.7
4.34
And I'll go ahead and save that as well.
3,811.04
4.083
So I've now created four airports.
3,815.123
1.417
I've created a flight and saved it.
3,816.54
2.13
If I type F just for my flight, I see that, all right,
3,818.67
3.84
this is a flight from New York to London.
3,822.51
2.73
But I can also say what is f.origin, and to write f.origin,
3,825.24
5.49
that is now an airport object.
3,830.73
1.92
It's JFK, in particular.
3,832.65
1.26
And I can do f.origin.city to get the city of the origin, which is New York.
3,833.91
4.58
f.origin.code to get the code of that airport, which is JFK.
3,838.49
4.33
And if I start with an origin, something like JFK or London Heathrow,
3,842.82
3.9
I can say LHR.arrivals.all to get all of the arrivals, all
3,846.72
6.48
of the flights arriving in London Heathrow.
3,853.2
2.038
And it looks like there's just one of them, which
3,855.238
2.042
is this flight that I've just created from New York that
3,857.28
3.15
is going to London as well.
3,860.43
2.58
And so this now gives us the ability to manipulate SQL
3,863.01
3.3
just by using these Python models.
3,866.31
1.82
And I now have Python classes that represent
3,868.13
2.59
all of these various different types of data.
3,870.72
2.19
And now, instead of running SQL queries like select star
3,872.91
2.61
from flights or from airports, I can just
3,875.52
2.16
interact with these classes and these properties on the classes,
3,877.68
3.9
and Django takes care of the process for me
3,881.58
2.28
of figuring out what the underlying SQL queries should be,
3,883.86
3.03
executing those queries, and just giving those results back to me.
3,886.89
3.78
And we can begin now to design a web application around this idea.
3,890.67
3.9
That I can go into urls.py, and lets add a url pattern that says,
3,894.57
3.96
the default route.
3,898.53
1.44
We'll go ahead and load the index view.
3,899.97
2.19
Give it a name of index.
3,902.16
1.2
Same as similar things we've seen from last time.
3,903.36
3.12
And now, what should we do in the index view?
3,906.48
3.06
Well, the index view, let's go ahead and say, what I would like to do
3,909.54
4.17
is just display a list of all the flights.
3,913.71
2.94
So I might from.models import flight and airport.
3,916.65
5.76
Or maybe I just need flight.
3,922.41
1.297
I just want a list of all the flights.
3,923.707
1.583
So I'm going to import flight from all of my models.
3,925.29
2.89
And now, what I'd like to do is return--
3,928.18
2.36
let's go ahead and render a template called flight/index.html,
3,930.54
4.8
and give index.html access to a variable called flights.
3,935.34
4.62
And what is that variable going to be equal to?
3,939.96
2.27
It's going to be equal to flight.objects.all
3,942.23
3.25
to get me all of the flights that I would like to put right here.
3,945.48
4.89
All right, so what can I do from now?
3,950.37
1.66
Now, what I need to do is actually create those individual templates.
3,952.03
3.38
So inside of flights, I'll create a new folder called templates.
3,955.41
5.01
Inside of which I'll create a new folder called flights.
3,960.42
2.88
Inside of which I'll go ahead and create a layout.html,
3,963.3
2.73
much as we've done before, where that layout
3,966.03
2.22
is going to contain the basic structure of our HTML page.
3,968.25
4.56
So a head section whose title is flights, and a body section that
3,972.81
6.1
is going to have a block body, and the end of the block.
3,978.91
5.31
Much as before, this is the default layout for this particular page.
3,984.22
4.2
And then, I'll add a new template called index.html that is going to extend
3,988.42
5.31
flight/layout.html.
3,993.73
2.67
And then, inside the body of the page, I'm
3,996.4
4.23
going to display an H1 that just says flights.
4,000.63
3.21
And let's now create an unordered list where I can now
4,003.84
2.67
loop over for flight in flights.
4,006.51
3.51
endfor to end the loop.
4,010.02
1.53
But inside the loop, let me create a list item
4,011.55
2.65
where I just print out a flight--
4,014.2
3.44
maybe I'll print out the flight and then flight.id
4,017.64
3.9
to print out flight 1, flight 2, flight 3.
4,021.54
2.4
And then, I'll print flight.origin to flight.destination.
4,023.94
6.1
So what I've done here is create a template
4,030.04
3.32
that I'm going to give access to a variable called flights, where flights
4,033.36
3.57
is going to be a variable that represents all of the flights
4,036.93
3.39
that I queried by running flight.objects.all, that is my way
4,040.32
3.72
using Django's API, using the functions that it has given me access to,
4,044.04
3.48
to say, take the flight and get all of the flights that are stored inside
4,047.52
4.56
of Django's database.
4,052.08
1.44