text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
So I can specify, I would like to use these particular settings
5,924.97
3.61
when you view the admin interface.
5,928.58
2.85
And so now, if I go back and go ahead and click on flights,
5,931.43
3.78
then now in this list display, whereas before I only
5,935.21
3.03
saw IDs and origins and destinations, now I
5,938.24
2.52
can configure it to show me all of the IDs and origins and destinations
5,940.76
3.75
and durations as well.
5,944.51
1.38
I've been able to configure this display to work the way I would like it to.
5,945.89
3.96
And there are other configurations you can do as well.
5,949.85
2.4
One that I quite like to use is if I want to update my passenger admin,
5,952.25
3.84
so when I'm editing a passenger, you can have
5,956.09
3.12
a special way of manipulating many to many relationships inside
5,959.21
3.57
of an attribute called filter horizontal.
5,962.78
2.85
And if I use a horizontal filter on flights,
5,965.63
3.48
this will just make it a little bit nicer for manipulating
5,969.11
2.79
the flights that a passenger is on.
5,971.9
1.62
And again, the specific syntax of this not as important as the idea
5,973.52
3.06
that these are all just configurable settings that Django has documented.
5,976.58
3.27
That you can look at to see how to configure the Admin interface to work
5,979.85
3
exactly the way you want it to work.
5,982.85
2.85
And so now, if I go back home and go to passengers,
5,985.7
2.99
and maybe click on a passenger like Harry Potter,
5,988.69
2.58
I now see this horizontal filter, which is
5,991.27
2.28
a very nice way of being able to manipulate flights
5,993.55
2.82
that the person is on.
5,996.37
1.17
I see on the left a list of their available flights
5,997.54
2.16
that I could add them to.
5,999.7
1.47
On the right, a list of their chosen flights.
6,001.17
1.98
Flights that they're already on.
6,003.15
1.53
And it becomes very easy for me to just take a flight and double click on it
6,004.68
3.75
to move it from an available flight to a flight that they're on and vise versa.
6,008.43
4.05
Just very quickly being able to control and manipulate these models.
6,012.48
3.57
And this is all stuff that Django just gives to you right out of the box.
6,016.05
4.89
So Django now has given us a lot of features.
6,020.94
2.32
The ability to represent models very succinctly.
6,023.26
2.6
A migration method for being able to very quickly apply
6,025.86
2.64
those changes to our database.
6,028.5
1.92
And the last thing we'll take a look at is this idea of authentication.
6,030.42
3.668
That on many websites, we want some method of authentication.
6,034.088
2.542
Some ability for users to be able to log in and log out.
6,036.63
3.15
For Django to remember who a particular user happens to be.
6,039.78
3.57
And what we're going to do now is introduce
6,043.35
1.83
an application that lets us interact with this authentication method.
6,045.18
3.7
Because Django has a whole bunch of authentication features
6,048.88
2.78
built right into the framework that we can take advantage of so
6,051.66
2.87
that we don't need to rewrite all the logic for how do you log someone in,
6,054.53
3.55
and what does it mean to represent the user.
6,058.08
1.89
Django has done a whole lot of that for us.
6,059.97
2.7
So we'll go ahead and create an application to do that now.
6,062.67
3.1
All right, so let's go back into my terminal now.
6,065.77
2.18
And now, I have this airline project inside
6,067.95
2.01
of which is one app called flights.
6,069.96
1.86
And I'd like to now create another app that's going to maintain users inside
6,071.82
3.18
of this application.
6,075
1.3
So I'll go ahead and run python manage.py start app users.
6,076.3
3.89
Which will just be an app that's going to allow me to represent users.
6,080.19
3.63
As before, when I create a new application,
6,083.82
4.01
I'll need to go into settings.py.
6,087.83
2.08
Add users as one of the installed apps inside of this project.
6,089.91
5.46
And I'll go into urls.py to say I'd also like when I go to users,
6,095.37
6.44
we'll go ahead and include users.urls.
6,101.81
4
So all the URLs that are associated with my user's application.
6,105.81
3.75
Now, I'll need to actually create those URLs.
6,109.56
2.51
So I'll go ahead and go down into my users application,
6,112.07
3.05
create a new file called urls.py, inside of which
6,115.12
3.74
is the same as what we've normally see inside of these URLs files.
6,118.86
3.15
I need to import path, import my views, and then define some URL patterns.
6,122.01
4.125
Where here what I'd like to do is define one path that takes me to views.index.
6,128.75
7.4
And we'll call this one index.
6,136.15
2.01
Then I'll create another path that takes me to log in, called the log in view.
6,138.16
6.01
And the name will be log in.
6,144.17
2.36
And we'll have another path called log out for a function called log out
6,146.53
4.85
view that will be associated with it.
6,151.38
2.258
So we'll effectively have three different routes.
6,153.638
2.042
One main index route that's just going to display information about the
6,155.68
3.09
currently signed in user.
6,158.77
1.6
One route for logging someone in, a form that
6,160.37
1.94
will display the place where they can type in a user name
6,162.31
2.4
and password to log in.
6,164.71
1.26
And then, one route to allow users to be able to log out from this application
6,165.97
4.08
as well.
6,170.05
1.285
So let's go ahead now and actually write these functions.
6,171.335
2.375
We need one function called index, one function
6,173.71
2.07
called log in view, one function called log out view.
6,175.78
3.57
So we'll go into views.py, and we'll start with index.
6,179.35
4.22
And so what does the index function need to do?
6,183.57
1.96
It's going to display information about the currently signed in user.
6,185.53
3.84
That I sign into this website, and then I'm presented with the index page.
6,189.37
3.83
Because if we think about this programmatically,
6,193.2
2.14
we first need to think about what should happen
6,195.34
2.4
if someone tries to access this page but they're not authenticated.
6,197.74
3.9
How would we even find that out, and what do we do in that situation?
6,201.64
3.1
Well, let's say, if not request.user.is_authenticated.
6,204.74
6.25
The request object that gets passed in as part of the request
6,210.99
2.84
to every user in Django automatically has
6,213.83
2.27
a user attribute associated with it.
6,216.1
2.22
And that user object has an is authenticated attribute that tells us
6,218.32
4.08
if the user is signed in or not.
6,222.4
2.4
If they're not signed in, we'll go ahead and HTTP response
6,224.8
3.9
redirect them to the log in view.
6,228.7
4.442