1
00:00:00,230 --> 00:00:01,040
Hey, welcome back.

2
00:00:01,040 --> 00:00:04,010
We're going to continue working on the admin interface.

3
00:00:04,010 --> 00:00:13,820
So far we only have this here to customize the admin interface sides, meaning that we can add some

4
00:00:13,820 --> 00:00:22,070
more fields here, more columns to show some more data about the users in the summary view here.

5
00:00:22,070 --> 00:00:30,860
And we can also add some functionality here, some features where the admins can filter the data by

6
00:00:30,860 --> 00:00:32,600
specific fields.

7
00:00:32,600 --> 00:00:41,600
So to do all that you need to go back to the admin.py file which is inside job application and between

8
00:00:41,600 --> 00:00:50,690
the import statements and the registration of the form, you want to create a class form admin.

9
00:00:50,690 --> 00:01:02,070
So I give this this name because the module is called form and it makes sense to call this form admin.

10
00:01:02,070 --> 00:01:07,770
This inherits from admin dot model admin.

11
00:01:07,770 --> 00:01:13,440
So this is a class designed to create admin interfaces.

12
00:01:13,800 --> 00:01:19,260
So basically we are modifying the default model admin.

13
00:01:19,380 --> 00:01:25,950
Now this class gets some specific variables such as list display.

14
00:01:26,640 --> 00:01:33,240
So if you give this variable you should give it exactly as you see the name here list underscore display

15
00:01:33,240 --> 00:01:34,950
with lowercase letters.

16
00:01:34,950 --> 00:01:45,420
So if Django finds this variable in this class, then what Django will do is it will display all these

17
00:01:45,870 --> 00:01:54,390
columns of the database table, such as first underscore name, last underscore name.

18
00:01:56,280 --> 00:02:00,030
Whatever you want to be displayed in this view here.

19
00:02:00,030 --> 00:02:02,970
You want to add those names in here.

20
00:02:03,390 --> 00:02:07,090
So these names should reflect these ones here, right?

21
00:02:07,110 --> 00:02:10,169
First name, last name, email, date, occupation.

22
00:02:10,169 --> 00:02:15,150
So these are the field names in the form model.

23
00:02:15,300 --> 00:02:15,720
Right?

24
00:02:15,720 --> 00:02:17,550
So let me go and refresh.

25
00:02:18,730 --> 00:02:28,270
And oh, that didn't change anything because oh, we forgot to add the form admin to register it right,

26
00:02:28,270 --> 00:02:29,500
because we created a class.

27
00:02:29,500 --> 00:02:36,310
But Django doesn't know what you mean by this class, so we need to add it to the register function.

28
00:02:36,310 --> 00:02:37,900
So you need to add the form.

29
00:02:37,900 --> 00:02:44,770
First form is the model from models.py and then comma form admin.

30
00:02:45,010 --> 00:02:46,830
Right, that's it.

31
00:02:46,840 --> 00:02:48,160
Let's refresh.

32
00:02:49,410 --> 00:02:52,090
This time we see this view.

33
00:02:52,110 --> 00:02:54,430
So now we have customized it.

34
00:02:54,450 --> 00:02:58,110
We want to see the first name, last name, email.

35
00:02:58,650 --> 00:03:00,150
So first name.

36
00:03:00,150 --> 00:03:01,140
Last name.

37
00:03:01,140 --> 00:03:01,980
Email.

38
00:03:03,690 --> 00:03:06,690
Search fields.

39
00:03:07,320 --> 00:03:08,480
Another variable.

40
00:03:08,490 --> 00:03:14,880
If you define this variable and you can then provide like again, a tuple.

41
00:03:15,890 --> 00:03:16,940
Like this.

42
00:03:18,630 --> 00:03:20,430
Let's go and refresh.

43
00:03:21,180 --> 00:03:30,150
So this time we have this search bar displayed here so you can type in something here and search for

44
00:03:30,150 --> 00:03:33,570
those fields that we defined in here.

45
00:03:33,930 --> 00:03:34,890
Next.

46
00:03:38,210 --> 00:03:39,650
The list filter.

47
00:03:40,730 --> 00:03:47,570
Let's try this time date and occupation.

48
00:03:47,720 --> 00:03:51,980
Let's go back to refresh and we've got this filter here.

49
00:03:52,370 --> 00:03:57,260
So in here you can filter by the date.

50
00:03:58,010 --> 00:04:05,250
So if you go to John, for example, John specified a date when they are available for the new job.

51
00:04:05,270 --> 00:04:13,940
So with that, if you go back to forms with that, you can filter only those job candidates who are,

52
00:04:13,940 --> 00:04:18,899
for example, available in the last seven days or this month or this year.

53
00:04:18,920 --> 00:04:24,500
So don't confuse this with the date when the entry was submitted by the user.

54
00:04:25,280 --> 00:04:27,780
To do that, you need to change the database.

55
00:04:27,800 --> 00:04:34,220
You need to add another field where you record the date of the registration of a record of a submission.

56
00:04:34,220 --> 00:04:35,900
So this is another thing here.

57
00:04:35,930 --> 00:04:38,070
And of course, by occupation.

58
00:04:38,220 --> 00:04:43,650
So if you click on student, you will see only the students here as an admin.

59
00:04:44,160 --> 00:04:44,750
Right.

60
00:04:44,760 --> 00:04:46,140
Let's go back to the code.

61
00:04:47,760 --> 00:04:49,380
You can also order.

62
00:04:51,140 --> 00:04:58,340
The data by specifying a string such as, let's say, first name.

63
00:05:00,800 --> 00:05:04,790
And don't forget to put a comma here so that this is actually a tuple.

64
00:05:07,660 --> 00:05:08,710
Refresh.

65
00:05:08,970 --> 00:05:10,840
Oh, we have the filter turned on.

66
00:05:10,840 --> 00:05:13,690
So click that to remove the filter.

67
00:05:14,020 --> 00:05:22,570
And now we see our deeds is the first one followed by John because it starts with an A and you can also

68
00:05:22,570 --> 00:05:24,730
order in reverse.

69
00:05:24,730 --> 00:05:29,320
To do that, you should write a minus just before first name.

70
00:05:29,320 --> 00:05:33,430
So inside the quotes and you go here, refresh.

71
00:05:33,430 --> 00:05:38,110
And now the order of the items has changed.

72
00:05:38,110 --> 00:05:39,580
So John is the first one.

73
00:05:40,310 --> 00:05:49,970
And lastly, if you go to one of these entries here and you can modify all these fields as an admin,

74
00:05:50,210 --> 00:06:01,580
but if you want to make one field read only, you can do that by specifying a read only underscore fields

75
00:06:01,910 --> 00:06:02,870
variable.

76
00:06:05,110 --> 00:06:07,910
So let's say occupation.

77
00:06:07,930 --> 00:06:13,090
Only occupation and the comma and go here, refresh.

78
00:06:13,090 --> 00:06:15,610
And now you can not change the student.

79
00:06:16,360 --> 00:06:21,220
And yes, that's how you work with the admin interfaces.

80
00:06:21,640 --> 00:06:27,940
So these are basically all you need to know about creating admin interfaces.

81
00:06:27,940 --> 00:06:29,350
So I hope this is useful.

82
00:06:29,350 --> 00:06:30,310
I'll see you in the next video.

