It's finally time to start calling the end of the course project.
As we said we're going to build a full fledged real world single page application and using django the
rest framework and Abuja.
Yes.
As you can see I'm currently inside the repository folder for this project.
It's always one of the most useful things that we can do when creating a new Django project is to initialize
a beautiful environment so that then inside of this V12 environment we can then install all the dependencies
that we're going to need.
And that's precisely what I'm going to do now.
So Python three dash M V and the anvil let's now activate pivot to environment.
So source B and being activate and the two packages that we want to install first are of course Django
and Django rest framework.
We are in fact when we started several other packages later on but for now we can't first of all create
the requirements that text file and we can now initialize our project.
So Django I mean start project question time and there it is.
So let's move inside of this folder.
We've got a project we're going to create two applications questions which is going to manage all the
code related to questions and answers such as for example models of views and so on and then we're going
to ever use this application which is the name clearly suggests it's going to manage all the code related
to the users on our platform and these users application is going to be the first one that we're going
to create now.
So Python managed that by start up users the new app is being created and we can now open up these words
to your code inside of this folder as always the first thing that we bother to do is to select the Python
interpreter for the project and we can see that the new virtual environment we've created in that Question
Time folder is available and we've done we can now install our users application in this setting stood
by file so you're users of course you also need to install Django framework.
So rest framework.
And considering that we're also going to use talking authentication we can also install rest framework
adopt of token.
And of course we also need a comma inside of the user's application.
We want to go to the models not by fine first.
And that's because for this project we want to use a custom user model even though we are not going
to add any fields to the model itself when developing something new is always a good idea to think about
the future of the project itself considering that we're developing a real world use case.
That project is in fact very similar to most more than social networks having the ability to update
the User model by design could be really really useful.
In the previous sections of the course we've seen how we can extend the User model using a profile model
but we've also talked about the fact that it was possible to extend the User model itself.
And so in order to do so first of all we're going to need to import the abstract user model from Django
dot country dot author dot models import abstract user.
And if you take a look at its definition we see that it extends abstract base use and permissions Maxine
providing us all the different fields that we're used to such as user name first name email ID stuff
and so on.
So the custom user model that we're going to create is in fact going to be very similar but one that
is already used by Django.
Let's go back to our models stood by file and here we can define class custom user extending abstract
user.
And here we can just use the bus instruction so that in the future in case you need to add new fields
to the custom user mother you can just remove the pass distraction and define all the different fields
that you might need.
They use it model is a very important part of the authentication system in a Django project and that's
why we now need to tell Django that we're using a custom model.
So let's go to the settings that by file by the end of the file.
Right here we now have to define off the user model equals users not cast on user.
That's no go to that I'd dead by file so that we can register a custom use that as well.
So you're going to board from Django dot country dot off dot Adgate.
I'm going to import user admin and of course the model itself.
So from users that models import custom user.
Now we are we can define a class class custom user admin which is going to extend user I've been the
one used as a default by Django.
Yet we have to define model custom user and then we can define list display is going to be a list of
course.
And yet we can set user name then email and then maybe is stuff in case you want to add other fields
to the custom user model.
Remember that year you then need to specify ad form where you can define a custom form class to use
to create new users and then a form class that you can instead use to update the different instances.
We can however just register the new class right away so admin dot site that register and we're going
to pass custom user and then of course custom user I mean like so is time to create and apply the migrations
for our new model.
So here Python managed that by make migrations and of course Python managed by migrate lets them create
a new user and specifically of course a super user so Python Mannix does by create super user you can
just call it Artemis let's nail Randy development server.
So first of all we are going to set up at configuration and I want to have a Django configuration here.
I'm going to comment out as always no threading.
So let's run the development server.
Let's move to Chrome and yet we can just go to slash.
I mean I mean and as you can see we have Art users application and we can always check and update if
we need you to.
All the information about our user now that everything is working fine.
We need to set that project so that users can create new accounts and authenticate them.
And in order to do so as we've seen in the previous sections we need to install a couple of packages.
Beep first of all people install Django rest of their winning free style Django or Laufer.
So people who start Django are lawful and then you can start Django registration which provides us all
the views needed to create new accounts in your browser.
And then we can install Django Krispie forms to create good looking forums easily that's now move to
the settings not by file because of course we need to register all the new applications we've just installed.
So first of all I love then we're going to have a Olof that so show and all of the social account then
yes we need to install rest of them and rest of the registration.
And as you might remember we also need to add another application this time one of Django is applications
which is Django country.
That sites and let's not forget crispy forms of course crispy forms.
And if you've never heard about this package it's a really useful package we use to create good looking
forums and as we'll see using it is very easy.
First of all we need to define down here Crispy template Tucker.
Yeah we define how we want our forums to look like in this case we want him to look like bootstrap for
for himself.
And of course later on we'll see how to actually use them in the HDMI templates.
We don't need to set aside ideas to one for the site's application and to register new accounts via
arrested.
We want to disable the email verification settings.
Yeah we can do account email vilification and can set none.
But we want a user to actually include an email anyway so account email required equals through and
let's also add some comments.
So this is about the custom user model.
This is about Django Krispie forms.
This is about Django country that sites and this is about Django Olof.
Now that all the settings are in place and in fact this is not a loft not social but all of that account.
Now that everything is in place let's apply all the migrations for the new applications.
So Python managed that by migrate and lets them move to the Urals not by file in order to define all
the different rural parts and end points for a project.
First of all right here I'm going to define path API author like so and yeah we can include rest framework
that you also then come up like so and yeah we can define API slash rest author to include rest of dot
your Elsa and then let us paste it once again like so including registration end point we arrest.
So this is going to be API rest of the registration.
And yeah we can include the rest of the dot registration don't to adults.
So this is about logging in your browser while API.
Logging of your arrest and registration of your arrest.
We now need to add it looking and the registration parts to use your browser.
That's out the logging one first so path.
And yet we can simply define accounts and we can include the normal URLs used by Django Django of the
country.
Not often thought your answer regarding the registration parts instead.
Things are going to be a little bit different.
We're going to use the views provided by the Django registration package even though those views expect
us to use a default user model.
And considering that of course we're using a custom user.
We also need to create a custom forum to use with django registration.
So yeah we can create a four by file like so and yeah first of all from django registration forms.
Import registration form and yeah of course from users not models.
Import custom user and then you do we can define classic custom user form which is going to extend the
registration form and yet inside we can define classic meta which can extend registration form that
matched up so that year we only have to define model equals custom user.
We can now import the form in that you arrested by file.
So from users that forms import custom user form so that we can now use it with the registration view
provided by django registration.
So yeah are only to import it of course from django registration dot McCann's DOT wants to epic that
museum import registration view and not this year I am using their one step views so that we can skip
email verification for now but I can include the are illegal to that django registration and documentation
so that you can learn how to set up an email verification system in case you need to.
Let's not create the path itself so I'm going to copy this one like so and this is going to be accounts
register and yet I'm just going to use registration of you dot s view and you don't need to pass a series
of parameters.
First of all form Classic which is going to be of course custom user form and then we need to pass this
access you had l we can just set it as deep on page and any idea we also need to set a name for the
path.
So name and we have to set it as Django registration and this core register.
But let's also include all the other you add else provided by the package.
So specifically I'm just going to copy these strings like so that's why I'm going to include Django
distillation that McCance not one step to address.
So let's make a brief recap of what we have here.
First of all of course the admin area.
So then we have a path to this custom version of the registration view provided by django registration
that we use to create new accounts via your browser.
Then we have other you add s used by the django registration package.
The log in your Ls provided by Django to log in users via a browser.
Then we have log in the URL for the browser API the log in and points to use the arrest and the registration
and point to use the arrest whilst being dead.
We need to do is to go to the settings notify file and now we need to set logging trail equals counts
logging then logging redirect you have l equals just the page and then logout at a direct link and we
can set the page as well so that after log out considering that the on page will only be available to
authenticated users looking for will be shown right away.
So this is it for this lesson.
We'll see how to set the rest of the authentication components such as for example the templates in
the next one.