text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
to only get passengers that
match a particular query, | 5,623.64 | 3.61 |
there's also a way in Django to say
passenger.objects.exclude to say | 5,627.25 | 4.73 |
exclude passengers that
satisfy a particular query. | 5,631.98 | 3.82 |
So I want to exclude passengers
who, among their flights, | 5,635.8 | 3.65 |
have this as one of their flights. | 5,639.45 | 3.15 |
And so what does this actually mean? | 5,642.6 | 1.69 |
Well, it means that when
I render flight.html, | 5,644.29 | 2.63 |
there's a couple pieces of
information that it should have. | 5,646.92 | 2.61 |
It needs to know what
flight is being rendered. | 5,649.53 | 2.34 |
It needs to know who is on the
flight, who are the passengers. | 5,651.87 | 3.13 |
But if I want a dropdown where
I can choose from all the people | 5,655 | 2.69 |
who aren't already on
the flight, like I would | 5,657.69 | 2.13 |
like to register you for
the flight, well, I also | 5,659.82 | 2.49 |
need all of the non-passengers. | 5,662.31 | 1.53 |
Passengers except, excluding the
ones who are already on the flight, | 5,663.84 | 5.52 |
and get me all of them is what
that .all is ultimately saying. | 5,669.36 | 4.2 |
And so using that, I now
have access to this variable | 5,673.56 | 3.27 |
called non-passengers that I can
use as I'm constructing this page. | 5,676.83 | 5.07 |
So back on flight.html, I can say,
for every passenger in non-passengers, | 5,681.9 | 7.74 |
let me create a option
that I can choose from. | 5,689.64 | 4.6 |
And the options value is going
to be the passenger's ID. | 5,694.24 | 5.02 |
Because ultimately, when I submit
the form, what I care about getting | 5,699.26 | 3.42 |
is what is the ID of this passenger
that I've chosen from this dropdown. | 5,702.68 | 4.145 |
But of course, the user
who's looking at this page, | 5,706.825 | 2.125 |
they don't want to see people's IDs. | 5,708.95 | 1.59 |
They want to see people's names. | 5,710.54 | 1.74 |
So inside of the option
tag, we'll go ahead | 5,712.28 | 2.7 |
and just print out the passenger's name. | 5,714.98 | 2.66 |
And we'll see in a
moment what all of this | 5,717.64 | 1.75 |
actually looks like in terms of HTML. | 5,719.39 | 2.47 |
So now that I've created
this form, I'll also | 5,721.86 | 2.54 |
need at the bottom to add an
input whose type is submit | 5,724.4 | 3.12 |
to let myself submit this form to. | 5,727.52 | 2.94 |
Let's now try running this application. | 5,730.46 | 2.63 |
It looks like there's
a slight error where | 5,733.09 | 1.75 |
I said view.book instead of views.book. | 5,734.84 | 2.063 |
Views is the name of the module,
since it's in a file called views.py. | 5,736.903 | 2.917 |
And now, it looks like
my server is running OK. | 5,739.82 | 3.54 |
I can go back to /flights. | 5,743.36 | 2.07 |
Let me get one of the flights, like
New York to London, flight number one. | 5,745.43 | 3.53 |
And all right. | 5,748.96 | 0.64 |
Name error. | 5,749.6 | 0.99 |
Name passenger is not defined. | 5,750.59 | 1.56 |
This is how Django renders to me errors
that are occurring in my Python code. | 5,752.15 | 3.63 |
Looks like it just means inside of
veiws.py I'm referencing passenger, | 5,755.78 | 4.65 |
but I never imported it. | 5,760.43 | 1.02 |
So up at the top, I'll go ahead
and import passenger as well. | 5,761.45 | 4 |
Now, it seems that my web
application is working OK. | 5,765.45 | 2.3 |
So now, hopefully, I refresh this
page, I see flight information. | 5,767.75 | 4.09 |
I see passengers. | 5,771.84 | 1.12 |
And I also down at the bottom
now see an add passenger section | 5,772.96 | 3.79 |
with a dropdown list. | 5,776.75 | 1.15 |
Where I can click on it
and see, all right, here | 5,777.9 | 2 |
are the three people that are
not already on this flight. | 5,779.9 | 3.45 |
And so if I want to add
Ginny Weasley to this flight, | 5,783.35 | 3.27 |
I can click Ginny Weasley, click
submit, and that submits the form. | 5,786.62 | 3.84 |
And I'm redirected back
to the same flight page. | 5,790.46 | 2.49 |
Now, Harry and Ginny
are both on the flight. | 5,792.95 | 2.16 |
And in the add passenger list, I see
Ron and Hermione as the options for me | 5,795.11 | 5.33 |
there. | 5,800.44 | 1.34 |
And so using Django's models, I've
been able to very quickly build up | 5,801.78 | 3.08 |
a reasonably sophisticated application. | 5,804.86 | 1.89 |
An application that has models, that
displays that information to me, | 5,806.75 | 3.66 |
and lets me manipulate that data. | 5,810.41 | 1.62 |
And that data is ultimately
stored inside of a SQL database. | 5,812.03 | 4.21 |
And one of the big powers of
Django that it really gives to me | 5,816.24 | 2.87 |
is this admin interface
that I ordinarily | 5,819.11 | 3.03 |
might have had to spend a lot of time
designing a web interface that just | 5,822.14 | 3.39 |
lets me do things like take some
person and go ahead and update | 5,825.53 | 4.11 |
what is their name, what
flights are they on, | 5,829.64 | 2.04 |
and the ability to very quickly
add and delete and edit the models | 5,831.68 | 3.88 |
is something that in a web application
could take quite a lot of time | 5,835.56 | 3.32 |
to be able to build from scratch. | 5,838.88 | 1.56 |
But Django, very fortunately,
gives all of that right to me. | 5,840.44 | 3.84 |
And this admin interface, even
though it is designed by Django, | 5,844.28 | 3.03 |
it's very customizable
in terms of things | 5,847.31 | 1.86 |
that I can do on this admin interface if
I want to manipulate it in certain ways | 5,849.17 | 4.47 |
in order to add additional
features to it as well. | 5,853.64 | 3.22 |
So we'll see a couple of
brief examples of this. | 5,856.86 | 2.21 |
If I go into admin.py,
here's my configuration | 5,859.07 | 3.96 |
for Django's admin interface. | 5,863.03 | 1.97 |
And I can say, I would
like to configure the admin | 5,865 | 2.92 |
interface in a particular way. | 5,867.92 | 1.83 |
That in a flight, for
example, by default all I saw | 5,869.75 | 3.06 |
was the flight's origin and destination. | 5,872.81 | 2.22 |
If I want to be able to see
more information about a flight, | 5,875.03 | 2.58 |
I can say, go ahead and give me a
class called flight admin, which is | 5,877.61 | 4.26 |
going to be a subclass of model admin. | 5,881.87 | 3.54 |
Where I can specify
any particular settings | 5,885.41 | 2.76 |
that I want to apply to how the
flight admin page is displayed. | 5,888.17 | 4.3 |
So I can-- and all of this is
documented on Django's website. | 5,892.47 | 2.56 |
And you just have to read it to be able
to know what configuration options are | 5,895.03 | 3.25 |
available to you. | 5,898.28 | 1.18 |
But I can say, in the list display,
when you list all the flights | 5,899.46 | 3.2 |
and display them all to me, what
field should I have access to? | 5,902.66 | 3.39 |
Well, go ahead and show me
something like the origin | 5,906.05 | 3.45 |
and the destination and the duration and
maybe also show me the ID, for example. | 5,909.5 | 6.03 |
So I want to see all of this
information when you load a flight. | 5,915.53 | 3.42 |
And when I register the flight,
I'll say register this flight, | 5,918.95 | 3.09 |
but use the flight admin
settings when you do so. | 5,922.04 | 2.93 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.