text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
There are a number of unexpected results that
2,787.35
1.96
can happen when we deal with problems related to race conditions
2,789.31
3.3
where multiple things are happening simultaneously.
2,792.61
2.83
How do we solve those problems?
2,795.44
1.49
Well, one strategy is to sort of place a lock on the database.
2,796.93
3.3
To say, while I'm working on this database nobody else
2,800.23
2.88
can touch this data.
2,803.11
1.18
Let me finish this transaction, so to speak.
2,804.29
2.29
Finish working on this particular transaction and making all the changes
2,806.58
3.31
I need to make to the database.
2,809.89
1.47
Only after I'm done I can release the lock and let someone else go ahead
2,811.36
4.26
and modify the database as well.
2,815.62
2.1
So a number of concerns to be aware of as we
2,817.72
2.37
begin dealing in this world of SQL and trying to work with databases.
2,820.09
5.43
So now that we've taken a look at the syntax of SQL,
2,825.52
2.28
understanding how these tables work, how they're structured,
2,827.8
3.03
and what it is that we can add to those tables,
2,830.83
2.23
let's go ahead and turn our attention in particular to Django
2,833.06
3.05
models, which are a way of representing data inside of a Django application.
2,836.11
4.098
Because where Django is really going to get powerful in designing our web
2,840.208
3.042
applications is the ability to represent data in terms of these models.
2,843.25
4.468
So we're going to go ahead and try to create a web application that
2,847.718
2.792
is going to represent what an airline might want to store inside
2,850.51
3.9
of its own web application.
2,854.41
2.7
All right.
2,857.11
0.5
So the first thing I want to do is create a Django project.
2,857.61
3.16
So I'll go ahead and type Django-admin START PROJECT
2,860.77
2.955
and the name of my project will just be called "airline."
2,863.725
2.375
I'm creating a project for an airline's website for example.
2,866.1
3.37
I'll go ahead and go into the airline directory,
2,869.47
2.06
open that up in my code editor.
2,871.53
1.78
Before I actually begin editing any code,
2,873.31
2.37
remember that every Django project needs to have one or more apps within it.
2,875.68
4.32
So the first app that I'll create for this airline
2,880
2.61
is an app for keeping track of flights.
2,882.61
3.15
So keeping track of flight related information,
2,885.76
2.7
like origins and destinations and durations
2,888.46
2.31
and what passengers are on those flights.
2,890.77
2.91
When I create a new app, first thing I'll need to do
2,893.68
2.97
is go into settings.py inside of airline,
2,896.65
2.88
and go ahead and add this app as an installed app.
2,899.53
3.36
So "flights" is now an app that I have installed.
2,902.89
3.15
Then what I'll want to do is say, go ahead and go into urls.py, which is,
2,906.04
6.662
again, that table of contents for all the
2,912.702
1.708
URLs I can get to for this particular web application.
2,914.41
2.46
I'll IMPORT include, because I want to do is when someone visits the path
2,916.87
4.29
of flights/ something, I want to take them to flights.urls,
2,921.16
5.56
mapping them to the urls.py file that will be inside of my "flights"
2,926.72
4.82
application.
2,931.54
1.41
Of course, now I need a urls.py file inside of my "flights" application.
2,932.95
4.01
So I go into "flights" and create a new file that I'll call urls.py.
2,936.96
4.09
We can do from FROM.django.urls IMPORT path FROM .IMPORT views.
2,943.87
5.34
And then my URL patterns are going to go inside of this list right here.
2,949.21
4.9
But before I begin dealing with actual URLs,
2,954.11
2.15
the first thing I'm going to want to do is create some models.
2,956.26
3.28
Models are going to be a way of creating a Python class that
2,959.54
2.93
is going to represent data that I want Django to store inside of a database.
2,962.47
4.62
So when I create a model, Django is going
2,967.09
1.77
to figure out what SQL syntax it needs to use it to A-- create that table
2,968.86
4.08
but then B-- manipulate that table.
2,972.94
1.8
Selecting and updating and inserting anytime I make changes to those models.
2,974.74
4.71
So here what I can do is inside of every app that gets created--
2,979.45
3.54
in this case called "flights"-- there is a models.py file.
2,982.99
3.35
We haven't looked at this before, but this
2,986.34
1.75
is going to be the place where we get to define what models
2,988.09
2.98
are going to exist for our application.
2,991.07
2.79
Every model is going to be a Python class.
2,993.86
2.31
You can think of this as having one model for each of the main tables
2,996.17
3.39
we care about storing information about.
2,999.56
2.62
So let me define a new class called "flight"
3,002.18
2.42
that is going to inherit from models dot model some creating a new class
3,004.6
3.48
called "flight" that is going to be a model.
3,008.08
3.75
Then I need to provide inside of this class all of the parameters
3,011.83
3.69
that a flight has.
3,015.52
0.77
What properties does a flight have that I might want to keep track of?
3,016.29
3.76
Well, a flight has an origin.
3,020.05
2.13
And the origin is going to be a models.charfield.
3,022.18
3.51
This is all documented on Django's website
3,025.69
1.83
in terms of the various different types of fields that exist that I
3,027.52
3.3
can include inside of a Django model.
3,030.82
2.25
Where here I'm saying here is a character field
3,033.07
2.71
whose max length is going to be 64.
3,035.78
3.34
I assume that most city names are not going to go longer than 64 characters.
3,039.12
3.34
That seems like a reasonable maximum length for the origin of the flight,
3,042.46
3.72
for example.
3,046.18
1.32
Every flight will also have a destination,
3,047.5
1.98
which will be a character field whose max length is also 64.
3,049.48
4.41
Every flight will have a duration, which will just be an integer field.
3,053.89
4.68
So now this is my very first Django model.
3,058.57
3.03
It is a class called "flight" where I've defined all of the properties
3,061.6
3.87
that a flight has, and then using Django syntax to find
3,065.47
2.85
what type they should have as well.
3,068.32
1.56
Every flight has an origin, has a destination, and has a duration.
3,069.88
5.31
But of course nothing here is actually modified
3,075.19
2.07
the database the Django is using in order to store information
3,077.26
3.93
about my web application.
3,081.19
1.2
And we can see if we, in fact go back to airline,
3,082.39
2.32
and I type LS, what you see here is that there isn't yet a database that exists.
3,084.71
5.61
I just have an airline directory, a flights directory,
3,090.32
2.69
and a manage.py file.
3,093.01
2.52