text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
So inside of models.py, I have a
class called airport and a class | 4,365.78 | 3.72 |
called flight. | 4,369.5 | 1.51 |
And if we look at the
files I have, there's | 4,371.01 | 1.88 |
another file we haven't really looked
at yet called admin.py inside of my app. | 4,372.89 | 4.77 |
And inside of admin.py, I'll first from
my models import flight and airport. | 4,377.66 | 6.24 |
And now, I'm going to say,
admin.site.register airport. | 4,383.9 | 4.41 |
And admin.site.register flight. | 4,388.31 | 4.88 |
And what this is going
to do is it is going | 4,393.19 | 2.11 |
to tell Django's admin app that
I would like to use the admin | 4,395.3 | 3.57 |
app to be able to manipulate airports
and to be able to manipulate flights | 4,398.87 | 4.59 |
as well. | 4,403.46 | 1.78 |
So let's take a look at this admin
app and see how it actually works. | 4,405.24 | 3.47 |
I can run python manage.py run server. | 4,408.71 | 4.35 |
That will start up the web server. | 4,413.06 | 1.92 |
I'll now visit this URL. | 4,414.98 | 1.23 |
Instead of going to
/flights I'll go /admin. | 4,416.21 | 3.39 |
And this opens up this
Django administration app | 4,419.6 | 3.94 |
that is not written by me. | 4,423.54 | 1.13 |
Django has written this, and
it's asking me to log in. | 4,424.67 | 2.82 |
I'll go ahead and log in using those
credentials I used a moment ago, typing | 4,427.49 | 3.36 |
in my username and password. | 4,430.85 | 1.59 |
And what I get here is Django's
site administration interface. | 4,432.44 | 4.5 |
Built for me by Django, where I
didn't need to design this at all. | 4,436.94 | 3.09 |
But importantly, if
we noticed down here, | 4,440.03 | 2.1 |
I now have the ability
to add and manipulate | 4,442.13 | 2.37 |
airports and flights via this
web interface, this Django | 4,444.5 | 3.51 |
administrative interface. | 4,448.01 | 1.15 |
So now, using this
interface, I have the ability | 4,449.16 | 2.54 |
to manipulate the underlying database. | 4,451.7 | 1.95 |
To manipulate my models to add and
modify data that already exists. | 4,453.65 | 4.74 |
So if I click on airports,
for example, I see here, | 4,458.39 | 2.78 |
here are all of the airports that
I've already added to my database. | 4,461.17 | 2.98 |
Tokyo, Paris, London, and New York. | 4,464.15 | 2.22 |
And I can add a new one. | 4,466.37 | 1.08 |
I can say, let's go ahead and
add PVG which is Shanghai. | 4,467.45 | 4.14 |
And I can either save it, save and
continue editing, save and add another. | 4,471.59 | 3.32 |
I'm going to add a couple, so I'll
go ahead and save and add another. | 4,474.91 | 2.875 |
Let's go ahead and add
Istanbul airport as well. | 4,477.785 | 2.925 |
Let's add Moscow as an airport two, and
maybe one more, we'll add Lima as well. | 4,480.71 | 6.84 |
And I'll just go ahead and click save. | 4,487.55 | 1.62 |
And now, I've added a whole bunch of
airports all via this web interface. | 4,489.17 | 3.6 |
Django was originally created
for news organization that | 4,492.77 | 3.02 |
very quickly wanted to be
able to post articles and post | 4,495.79 | 2.65 |
new posts on their website. | 4,498.44 | 1.41 |
And it made it very easy
via an interface like this | 4,499.85 | 2.43 |
to very quickly just say,
here, add a new article | 4,502.28 | 2.52 |
and here's the content of the article,
to be able to display on a page. | 4,504.8 | 3.27 |
And now, we've been able to very
quickly add new airports to our website | 4,508.07 | 3.81 |
as well. | 4,511.88 | 1.03 |
And so if we want to add flights,
well, we can go ahead and go back home. | 4,512.91 | 5.09 |
Click on flights. | 4,518 | 1.38 |
I see that I already have two
flights inside of my database. | 4,519.38 | 2.58 |
I have New York to London
and New York to Paris. | 4,521.96 | 2.46 |
I'll add a new one. | 4,524.42 | 1.38 |
It's letting me choose an origin,
destination, and duration. | 4,525.8 | 2.88 |
And Django knows that the
origin must be an airport, | 4,528.68 | 2.67 |
so it's going to give me the
opportunity to just choose an airport. | 4,531.35 | 3.05 |
Where I can say, OK,
Shanghai is the origin. | 4,534.4 | 2.23 |
The destination is going to
be Paris, and the duration | 4,536.63 | 2.67 |
is going to be 760 minutes, for example. | 4,539.3 | 3.11 |
So now, using Django's
admin interface, I've | 4,542.41 | 2.27 |
been able to add a number
of different flights | 4,544.68 | 2.1 |
and a number of different airports. | 4,546.78 | 1.65 |
And if I go back, not to the
admin app, but to my flights app, | 4,548.43 | 3.78 |
the app that I wrote myself,
and go back to /flights. | 4,552.21 | 2.76 |
Now, I actually see
all of the new flights | 4,554.97 | 2.82 |
that I have added to my database
via Django's admin interface. | 4,557.79 | 3.463 |
I added them to the admin interface,
and now I see this flight from Shanghai | 4,561.253 | 3.167 |
to Paris. | 4,564.42 | 0.78 |
I see this flight from
Paris to New York as well. | 4,565.2 | 4.57 |
And so now, what I might
like to do is begin | 4,569.77 | 2.06 |
to add some more pages
to this web application. | 4,571.83 | 2.45 |
Make this web application
a little more sophisticated | 4,574.28 | 2.86 |
by maybe giving me the ability
to click on a particular flight | 4,577.14 | 3.72 |
to view details about that flight. | 4,580.86 | 1.98 |
What I'd like is for every
flight to have its own page, | 4,582.84 | 2.82 |
not just /flights for all the flights,
but /flight/one for flight ID one. | 4,585.66 | 4.86 |
/flight/two for ID two,
so on and so forth. | 4,590.52 | 3.72 |
What I can do in order to do
that is go back into urls.py | 4,594.24 | 4.41 |
and create a new path. | 4,598.65 | 1.44 |
We'll create a path where
I'm going to specify | 4,600.09 | 2.67 |
a flight ID, which would be an integer. | 4,602.76 | 2.73 |
When I do, let's go ahead and load the
flight view, whose name will be flight. | 4,605.49 | 4.32 |
And now, I need to just go to views.py
and add a function called flight. | 4,609.81 | 4.92 |
So I go back, go into views.py. | 4,614.73 | 2.34 |
In addition to an index function,
we'll define a flight function that | 4,617.07 | 4.14 |
accepts as an argument a flight ID. | 4,621.21 | 3.18 |
So now, what is the flight
function going to do? | 4,624.39 | 2.35 |
Well, the first thing I need to
do is actually get that flight. | 4,626.74 | 3.08 |
I can say flight equals
flight.objects.get. | 4,629.82 | 2.81 |
Get me the flight whose idea is
equal to flight ID, for example. | 4,632.63 | 6.34 |
Or alternatively, Django also
let's you say pk instead of ID. | 4,638.97 | 3.72 |
It's a much more generic
way of referencing | 4,642.69 | 1.8 |
the primary key, for whatever the
primary key happens to be called. | 4,644.49 | 3.36 |
The pk in this case is just the ID. | 4,647.85 | 2.31 |
But then what I can do is render a
template, like flight/flight.html, | 4,650.16 | 6.63 |
and pass as input to that the flight. | 4,656.79 | 3.63 |
So we're passing this
flight to flight.html. | 4,660.42 | 3.87 |
And now, I can create a template-- | 4,664.29 | 2.01 |
create a new file called flight.html
which is going to also extend | 4,666.3 | 5.73 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.