1
00:00:00,230 --> 00:00:01,150
Hey, welcome back.

2
00:00:01,160 --> 00:00:07,760
In this video, you learn how to create admin interfaces for your Django apps.

3
00:00:07,760 --> 00:00:14,720
So currently our Python, our Django app looks like this.

4
00:00:15,410 --> 00:00:21,920
So we get data from the users, but there is no easy way to access those data.

5
00:00:21,950 --> 00:00:23,240
As admins.

6
00:00:23,240 --> 00:00:32,689
So we have to use like a third party app, like DB browser for SQLite to view the database records that

7
00:00:32,689 --> 00:00:34,290
the user has submitted.

8
00:00:34,310 --> 00:00:38,300
So we can fix that by having an admin interface.

9
00:00:38,300 --> 00:00:45,220
So Django is made to actually make it easier for you to create admin interfaces.

10
00:00:45,230 --> 00:00:53,930
So if you look inside job application, the app folder you will find an admin.py file.

11
00:00:55,620 --> 00:01:03,960
So Django has already created a semi empty file, which now we need to add some more code, which is

12
00:01:03,960 --> 00:01:05,700
very minimal code actually.

13
00:01:05,700 --> 00:01:13,950
So all you need to do is you need to import from DOT models import form.

14
00:01:14,100 --> 00:01:23,940
So dot models means this file models.py and form is the class that defines our database model.

15
00:01:24,150 --> 00:01:33,210
So we import form and then down here we use this module admin which is imported up here.

16
00:01:33,540 --> 00:01:36,510
Dot site dot register.

17
00:01:36,900 --> 00:01:43,260
The register function expects a class to register it with the admin interface.

18
00:01:44,960 --> 00:01:46,000
This class.

19
00:01:46,010 --> 00:01:47,450
The module class.

20
00:01:48,560 --> 00:01:58,400
You want to save that file and then to access the admin interface, you should go to your URL, but

21
00:01:58,400 --> 00:02:07,990
add a slash and then admin and press enter and you'll see this view where the admins can log in.

22
00:02:08,000 --> 00:02:14,240
Now in my case I have some pre-filled data here because I've built some other interfaces, other Django

23
00:02:14,240 --> 00:02:20,240
programs, but you probably will see like an empty set of fields, a username and password.

24
00:02:20,240 --> 00:02:21,770
So what's the username?

25
00:02:21,770 --> 00:02:24,560
Where can you get the username and the password?

26
00:02:24,560 --> 00:02:30,740
Well, for that you need to create a super user, an admin account basically.

27
00:02:30,740 --> 00:02:43,520
So go to your terminal, stop the program with ctrl C and run python manage.py Create super user.

28
00:02:43,520 --> 00:02:45,260
So it's one word.

29
00:02:45,290 --> 00:02:53,310
No spaces you want to execute that and you should be asked to enter a username.

30
00:02:53,310 --> 00:02:57,210
So I'll just enter my name press enter.

31
00:02:57,960 --> 00:03:01,500
Then you want to specify an email address.

32
00:03:01,530 --> 00:03:05,520
I'll just use the email address I was using for this app app.

33
00:03:05,850 --> 00:03:06,720
Django.

34
00:03:08,080 --> 00:03:14,440
It's not much important just for the records and press enter again to submit that.

35
00:03:14,530 --> 00:03:18,430
Then the passwords and so I'll type in my password.

36
00:03:18,430 --> 00:03:27,400
But note that the password is not visible, so I'm typing in as you can hear probably, and I don't

37
00:03:27,400 --> 00:03:30,670
see any asterisk or the password.

38
00:03:30,670 --> 00:03:33,730
So the password is being typed in, but it's hidden.

39
00:03:33,730 --> 00:03:40,030
So once you're typing the password, then you want to press enter and then type in the same password

40
00:03:40,030 --> 00:03:47,980
again just for confirmation, press enter again and you'll see this super user created successfully.

41
00:03:48,280 --> 00:03:53,830
And then we want to run the app again with Python Manage.py run server.

42
00:03:54,490 --> 00:03:57,100
Go to the admin interface.

43
00:03:57,100 --> 00:03:57,640
Right.

44
00:03:57,640 --> 00:04:00,820
So that's your URL.

45
00:04:02,920 --> 00:04:07,030
And then you want to enter your username and your password.

46
00:04:09,600 --> 00:04:10,650
Press login.

47
00:04:11,900 --> 00:04:15,080
And this is what you should normally see.

48
00:04:15,740 --> 00:04:25,050
So this is the site administration and you can have one or more admins to actually access this site.

49
00:04:25,070 --> 00:04:30,170
So we have several links here such as groups and users.

50
00:04:30,170 --> 00:04:38,510
So these are about the groups of users and the actual users themselves, like the user I've just created.

51
00:04:39,780 --> 00:04:41,160
And then.

52
00:04:41,920 --> 00:04:47,290
We have forms which you can access it from here or again from home.

53
00:04:47,440 --> 00:04:49,720
So that's forms.

54
00:04:50,710 --> 00:04:55,470
So this is the most important aspect of the admin interface.

55
00:04:55,480 --> 00:05:01,990
So forms represents the form table where we have the user data.

56
00:05:01,990 --> 00:05:07,150
So these are all the submissions I have received in my app.

57
00:05:07,150 --> 00:05:15,550
So again, wherever the users enter here, that submission will be displayed in here, right?

58
00:05:15,550 --> 00:05:17,020
So let's give it a try.

59
00:05:18,010 --> 00:05:21,070
Let's try John Smith.

60
00:05:22,230 --> 00:05:27,060
john@example.com

61
00:05:27,390 --> 00:05:28,680
enter a date.

62
00:05:32,550 --> 00:05:34,140
Student submit.

63
00:05:35,410 --> 00:05:40,400
Form submitted successfully and then we can go to the admin interface.

64
00:05:40,420 --> 00:05:46,510
You can reload this current link and then you'll see John Smith added there.

65
00:05:46,510 --> 00:05:53,800
So each of them now each of these records here is clickable, which means you can click it and you will

66
00:05:53,800 --> 00:05:55,510
see all the data.

67
00:05:55,660 --> 00:06:03,550
So again, here we see the list of submissions and we only see the names in the list.

68
00:06:03,550 --> 00:06:05,530
But then we have all these.

69
00:06:05,560 --> 00:06:10,790
And as an admin you can also modify these fields.

70
00:06:10,810 --> 00:06:15,550
It's also possible to make a field read only.

71
00:06:15,580 --> 00:06:18,190
I'll show you how to do that in the next video.

72
00:06:18,190 --> 00:06:22,300
So for now, this is all the default view.

73
00:06:22,300 --> 00:06:30,280
So you can delete, you can change records and save it, and you can also add records on your own.

74
00:06:30,280 --> 00:06:35,960
So you have this add button here, that one or that one, they do the same thing.

75
00:06:35,960 --> 00:06:39,770
So add form and you can add records on your own.

76
00:06:39,770 --> 00:06:44,010
So two ways to add a new job application, right?

77
00:06:44,010 --> 00:06:50,810
So one through the websites as visitor and one manually as an admin in this interface.

78
00:06:51,410 --> 00:06:55,220
So that's about how to create a default admin interface.

79
00:06:55,220 --> 00:07:00,260
In the next video, I'll show you some tricks on how to customize the admin interface.

80
00:07:00,260 --> 00:07:04,880
So we'll customize the list here and also make some fields reads only.

81
00:07:05,510 --> 00:07:07,700
So let's see how we can do that in the next video.

82
00:07:07,730 --> 00:07:08,210
See you there.

