WEBVTT

00:01.620 --> 00:02.340
Okay.

00:02.370 --> 00:07.470
In this video, I will show you how to see what's inside our database.

00:07.470 --> 00:12.260
And for this we'll use built in Django admin view.

00:12.270 --> 00:23.550
So if we go to our chrome, this is our admin view and the URL for this is this 127 001 which is localhost

00:23.550 --> 00:26.610
and then 8000 port and then slash admin.

00:26.610 --> 00:29.940
And you can see here it's a login page.

00:30.030 --> 00:37.140
At the moment we don't have any credentials and we can't, can't login in the Django administration

00:37.140 --> 00:37.680
here.

00:37.680 --> 00:44.190
The reason for this is we don't have a user in our system and we'll create a user on our system.

00:44.190 --> 00:49.740
I will show you how to do it and then how we can actually access this and manage Django administration.

00:49.980 --> 00:50.340
Okay.

00:50.340 --> 00:54.000
So let's go back to our IDE and let's create a user.

00:55.080 --> 01:01.720
So we are inside our terminal in IDE and I can run command in a similar way.

01:01.720 --> 01:02.740
We run it before.

01:02.740 --> 01:03.910
So Python.

01:04.910 --> 01:09.680
Three or just python if you have one installed on your machine.

01:09.890 --> 01:15.530
Manage pi and then create super user.

01:15.840 --> 01:18.050
Altogether create super user.

01:18.050 --> 01:20.210
And then we click enter.

01:20.840 --> 01:27.830
And then we have some message here about three unapplied migrations and the admin and out.

01:27.830 --> 01:32.330
And then they ask us to run the command python manage.py migrate.

01:32.360 --> 01:35.560
We already did it so we'll kind of ignore it for now.

01:35.570 --> 01:43.820
So basically this so actually might not have this displayed, but running this command, it will ask

01:43.850 --> 01:45.170
us for a few things.

01:45.170 --> 01:48.680
So basically first thing will be the username.

01:48.680 --> 01:55.880
If you will leave it blank, it will be the same user as you have on your machine and I have a user

01:55.880 --> 02:00.350
Christian, so I will leave it blank and I will click enter and then we have email address.

02:00.350 --> 02:04.890
You don't need to type anything here, but if you like you can put your email address.

02:04.890 --> 02:08.580
I will click Enter and then we need to set up a password.

02:08.610 --> 02:18.870
I will set a password like my username Christian and then Christian and it's too similar to the username,

02:18.870 --> 02:21.930
so I'll actually should create a different one.

02:22.260 --> 02:26.400
But for our tutorial needs I can leave it as it is.

02:26.580 --> 02:32.400
And because we are not really concerned about the security, but please don't put an application with

02:32.400 --> 02:38.010
the same username and password on the production server because you will put your application at risk.

02:38.010 --> 02:41.690
But we can bypass password validation and create user anyway.

02:41.700 --> 02:44.310
I can click yes and then enter.

02:44.310 --> 02:51.660
So we have created super user and we have that user with a username Christian and password Christian

02:51.690 --> 02:53.220
available for us to use.

02:53.220 --> 02:57.030
So that's been added to our database and that's an admin user.

02:57.030 --> 02:59.010
So if I'll come back to the chrome.

03:00.530 --> 03:01.610
We can see here.

03:01.610 --> 03:08.480
Username is Christian and the password will be Christian the same way I've done it just a second ago

03:08.480 --> 03:13.130
and I will log in here and I'm inside the Django administration.

03:13.130 --> 03:16.580
So basically this screen allows me to see everything.

03:16.580 --> 03:19.040
What's inside that database.

03:19.130 --> 03:22.490
As soon I will add it to the Django administration.

03:22.700 --> 03:25.910
And you can see here you have authentication and authorization.

03:25.910 --> 03:30.260
If I go to the users, you can see my user here.

03:30.260 --> 03:38.450
So I have a user and that's all information about my user I've created with create super user a command.

03:38.450 --> 03:46.700
So I have groups and users available and I can add new users here, I can change and I can do a lot

03:46.700 --> 03:56.210
of things here in that provided user interface, but we don't see our model the way that.

03:58.820 --> 04:03.950
The model we have created here book is at the moment not available in the admin.

04:03.950 --> 04:09.830
And the reason for this is we will need to add it manually to our admin file.

04:09.830 --> 04:14.330
So let's open admin and you can register your models here.

04:15.170 --> 04:22.190
So let's remove this and we can do admin side.

04:25.000 --> 04:33.510
Register and then we can put the same name here, which is book.

04:33.520 --> 04:36.490
So I will register here a book.

04:36.490 --> 04:38.380
But at the moment it's underlined.

04:38.410 --> 04:41.800
That means it's unresolved reference.

04:41.800 --> 04:44.350
So we need to import so from.

04:46.320 --> 04:46.860
Models.

04:48.580 --> 04:49.750
That's in the same folder.

04:49.750 --> 04:53.260
So dot models import book.

04:53.560 --> 05:00.560
Once we import book, the red line is gone and then we do admin site register our model.

05:00.580 --> 05:02.200
So if I will save it now.

05:06.400 --> 05:08.950
And then we'll refresh the server.

05:10.120 --> 05:14.470
I will go to the this view and I will refresh the page.

05:15.310 --> 05:17.110
And you can see here the demo.

05:17.140 --> 05:19.300
This is the name of our application.

05:19.300 --> 05:23.800
And then inside the demo we have one model, one model called books.

05:23.800 --> 05:31.540
And if I will go to the books, there is a zero books inside our database, but I can add book here

05:31.660 --> 05:38.980
and you can see here title is this field we specified in our models.

05:38.980 --> 05:44.710
So we have title and that's a char field maximum 36 character long.

05:44.740 --> 05:49.570
And this user interface represents this setup from the file.

05:49.570 --> 05:51.700
So we have a book with a title.

05:51.700 --> 06:04.300
Let's add a book here and I will add for example, Hobbit, I can do Save, and this represents a new

06:04.300 --> 06:06.020
record in our database.

06:06.020 --> 06:13.850
I can click on this and I can see here I can change it so I can change anything here and then save it.

06:13.880 --> 06:18.290
I can remove it from database or I can add more into it.

06:18.290 --> 06:22.310
So this user interface allows us to manage our database.

06:22.310 --> 06:27.140
So whatever you need to do on your database level, you can do it directly from here.

06:27.140 --> 06:33.710
So sometimes the Django application for Django application, the Django administration user interface

06:33.710 --> 06:40.190
will be enough for a application because if you want to store a simple records in the database and you

06:40.190 --> 06:44.900
need a simple user interface, you can use Django administration for that.

06:44.900 --> 06:50.990
You can log in with your super user and then you can add records, remove records and manage all records

06:50.990 --> 06:52.190
in one place.

06:52.460 --> 06:59.360
So in this video, I will show you how to use the Django administration and how to create a super user.
