1
00:00:00,200 --> 00:00:07,370
Hey, currently our app shows some dummy data, so we want to show some actual data which are coming

2
00:00:07,370 --> 00:00:08,540
from the database.

3
00:00:08,540 --> 00:00:13,220
But before we do that, we want to create an admin interface.

4
00:00:13,220 --> 00:00:17,510
And then as an admin we can add some actual data.

5
00:00:17,810 --> 00:00:25,400
So to create an admin interface, you want to go to the restaurant menu directory and there you will

6
00:00:25,400 --> 00:00:31,160
find an admin.py file which Django has automatically generated.

7
00:00:31,160 --> 00:00:33,430
But this is almost empty.

8
00:00:33,440 --> 00:00:44,090
So we want to create a class now called menu item admin which inherits from admin.

9
00:00:44,090 --> 00:00:47,990
So this name dot model admin.

10
00:00:50,220 --> 00:00:58,980
Capital, M capital A Then here we want to mention some predefined variable names such as List display

11
00:00:59,160 --> 00:01:03,720
the way we want the data to be displayed on the admin interface.

12
00:01:04,110 --> 00:01:06,720
So we want this to be displayed.

13
00:01:07,290 --> 00:01:14,640
We want to see the name and the status of the data, name and status on these are in Models.py.

14
00:01:16,550 --> 00:01:21,280
And actually it's Mele, Mele and status.

15
00:01:21,290 --> 00:01:24,650
So if the mele is available, you can use any of them.

16
00:01:24,650 --> 00:01:25,100
Right?

17
00:01:25,100 --> 00:01:26,810
So Mele not name.

18
00:01:26,810 --> 00:01:28,730
We don't have a name field.

19
00:01:28,730 --> 00:01:30,620
So these are database fields.

20
00:01:33,500 --> 00:01:34,820
List filter.

21
00:01:34,820 --> 00:01:36,770
So filter by status.

22
00:01:38,580 --> 00:01:40,470
Each of them is a tuple.

23
00:01:40,830 --> 00:01:42,450
Make sure to have a comma here.

24
00:01:42,480 --> 00:01:46,170
Otherwise Python will not read this as a tuple.

25
00:01:46,170 --> 00:01:51,270
And then search fields how you want to search this.

26
00:01:52,140 --> 00:01:58,890
So that would be meal and you want to search by meal and description.

27
00:01:58,940 --> 00:02:01,590
Description is also one of the fields.

28
00:02:01,740 --> 00:02:02,160
Let's.

29
00:02:02,160 --> 00:02:03,300
Yeah, it's here.

30
00:02:05,150 --> 00:02:06,620
And then this class.

31
00:02:06,620 --> 00:02:08,490
Let me make another line there.

32
00:02:08,509 --> 00:02:14,030
This class has to be registered with admin, dot, site, dot register.

33
00:02:15,440 --> 00:02:27,230
You want to couple that class with the item class which should be imported from DOT models import item.

34
00:02:28,140 --> 00:02:32,070
And then here you mention menu item admin.

35
00:02:33,050 --> 00:02:40,100
So basically this item model is coupled with this menu item admin.

36
00:02:40,790 --> 00:02:49,340
Now if you go to the site and you add the slash admin here, this will take you to the login form.

37
00:02:50,090 --> 00:02:54,860
But we need to create an admin here to be able to log in.

38
00:02:56,170 --> 00:03:03,520
To create the admin, you need to go to your Django project in PyCharm and you want to press control

39
00:03:03,550 --> 00:03:07,170
C in the terminal to stop the project.

40
00:03:07,180 --> 00:03:16,960
And then you want to run Python manage.py making sure that the venv is activated here and then the command

41
00:03:16,990 --> 00:03:19,150
is create super user.

42
00:03:20,770 --> 00:03:21,160
So.

43
00:03:21,160 --> 00:03:22,360
Python manage.py.

44
00:03:22,390 --> 00:03:27,040
Create super user press enter and this will ask you to enter the username.

45
00:03:27,040 --> 00:03:36,120
Let's keep it simple and say admin email address admin@admin.com.

46
00:03:36,130 --> 00:03:41,290
Just a simple email address for the records and then the password.

47
00:03:41,290 --> 00:03:43,380
I'll just write admin here as well.

48
00:03:43,390 --> 00:03:46,300
You'll not see anything when you type.

49
00:03:46,300 --> 00:03:48,250
So the password is hidden.

50
00:03:49,030 --> 00:03:50,680
So I typed in admin.

51
00:03:50,680 --> 00:03:52,090
Now I'll press enter.

52
00:03:52,840 --> 00:03:54,310
I'll repeat the password.

53
00:03:54,310 --> 00:03:56,380
Admin press enter again.

54
00:03:56,680 --> 00:04:03,040
If the password is too short, you'll get this question if you want to accept it or not.

55
00:04:03,040 --> 00:04:12,520
For simplicity, I'll just press y to accept it and then I can go in here and say admin admin login.

56
00:04:13,900 --> 00:04:16,300
Oh, sorry I didn't run the app.

57
00:04:16,540 --> 00:04:18,550
So you want to run the app again?

58
00:04:18,550 --> 00:04:22,190
Python manage.py run server with a port name or not.

59
00:04:22,220 --> 00:04:23,630
Whatever you prefer.

60
00:04:25,150 --> 00:04:28,780
So again, go to the URL and then slash admin.

61
00:04:30,750 --> 00:04:36,000
Admin admin login.

62
00:04:38,520 --> 00:04:40,940
And you should see this.

63
00:04:40,950 --> 00:04:49,250
So we have these default tables, groups and users and then we have the items table as well.

64
00:04:49,260 --> 00:04:55,260
So items comes from this modules here, the class item.

65
00:04:55,260 --> 00:04:57,630
So that name is reflected in here.

66
00:04:57,630 --> 00:05:04,470
If you press on items and then you want to add the new item using that button or that button.

67
00:05:04,470 --> 00:05:12,480
So what you're doing here, when you press that add item button is you are adding a new record to the

68
00:05:12,480 --> 00:05:14,690
items table, right?

69
00:05:14,700 --> 00:05:24,750
That record will have a meal such as pizza, a description such as dough and cheese.

70
00:05:24,960 --> 00:05:33,360
So this is like the ingredients, a price, let's say 9.9, a meal type.

71
00:05:33,360 --> 00:05:41,070
So this comes from the string here, meal type inside Models.py.

72
00:05:41,400 --> 00:05:50,370
So we have starters, we have salads, so we want to link one meal with a category of meal.

73
00:05:50,370 --> 00:05:53,880
So this would be a main dish.

74
00:05:54,540 --> 00:05:57,630
Author It's the admin, this is the username.

75
00:05:57,630 --> 00:06:00,150
We have just created status.

76
00:06:00,480 --> 00:06:03,480
So do you want to put it as unavailable or available?

77
00:06:03,480 --> 00:06:06,060
Let's put it available and press on save.

78
00:06:06,240 --> 00:06:07,170
So there we go.

79
00:06:07,170 --> 00:06:09,870
We have the pizza and the status available.

80
00:06:10,350 --> 00:06:20,550
So this is showing the meal and the status because that's what we defined in Admin.py meal and the status.

81
00:06:22,080 --> 00:06:24,690
And then we can filter by status.

82
00:06:24,690 --> 00:06:26,540
So list filter status.

83
00:06:26,550 --> 00:06:34,410
You see here, you can filter those and you can search here by meal and description.

84
00:06:35,100 --> 00:06:41,640
So this here define how this will look like the admin interface.

85
00:06:41,820 --> 00:06:43,770
Let's add one more item.

86
00:06:44,580 --> 00:06:46,230
Greek salad.

87
00:06:47,990 --> 00:06:52,340
Tomatoes, cheese, Onions, perhaps.

88
00:06:52,430 --> 00:06:57,920
And let's set the price to 8.5.

89
00:06:58,330 --> 00:07:00,260
A meal is salads.

90
00:07:00,440 --> 00:07:02,030
Author is the same.

91
00:07:02,030 --> 00:07:07,640
So you can have multiple authors, multiple cooks who can add meals.

92
00:07:07,640 --> 00:07:10,040
For that, you need multiple users.

93
00:07:10,040 --> 00:07:16,130
So you can go here and create more users which can access the admin interface.

94
00:07:16,130 --> 00:07:21,530
And so it's good to keep each meal connected to a particular cook.

95
00:07:21,530 --> 00:07:23,630
So you know who added what.

96
00:07:24,620 --> 00:07:27,500
Let's make this unavailable press on save.

97
00:07:28,370 --> 00:07:29,020
And there we go.

98
00:07:29,030 --> 00:07:30,590
Greek salads and pizza.

99
00:07:32,240 --> 00:07:32,600
Okay.

100
00:07:32,600 --> 00:07:37,010
I paused the recording and I added some more items just to have them here.

101
00:07:37,580 --> 00:07:45,090
So I do recommend you also add a few more items so that later on we can see these on the web page.

102
00:07:45,110 --> 00:07:51,830
Now, just before I close the video, I also wanted to show you that if you have a program such as DB

103
00:07:51,830 --> 00:07:56,960
browser for SQLite, you can actually display that table.

104
00:07:56,960 --> 00:07:59,360
So you don't have to do this.

105
00:07:59,600 --> 00:08:00,560
But.

106
00:08:03,330 --> 00:08:06,450
Just to demonstrate to you what we're doing here.

107
00:08:06,450 --> 00:08:08,910
So App 18.

108
00:08:09,920 --> 00:08:14,180
So in my PyCharm project I have this debug sqlite3.

109
00:08:14,210 --> 00:08:19,880
That's the actual database which is populated with the items we just added.

110
00:08:19,880 --> 00:08:22,160
So you can also view those items in here.

111
00:08:22,160 --> 00:08:28,520
You go to browse and then you find that restaurant menu item table and there we go.

112
00:08:28,520 --> 00:08:31,760
That's the data I have just added.

113
00:08:31,790 --> 00:08:32,900
Pizza, Greek salad.

114
00:08:32,900 --> 00:08:33,710
ET cetera.

115
00:08:33,980 --> 00:08:41,809
There are other tables here as well which are more like default tables, which Django has created.

116
00:08:43,159 --> 00:08:48,100
But the table that contains the data is restaurant menu item.

117
00:08:48,110 --> 00:08:53,780
The name is automatically chosen by Django.

118
00:08:53,780 --> 00:08:57,020
So restaurant menu items it reflects.

119
00:08:58,020 --> 00:08:59,730
This app name.

120
00:08:59,730 --> 00:09:10,020
So the app name restaurant menu followed by item, which is the name of the class here in Models.py

121
00:09:10,740 --> 00:09:12,780
are both in lowercase letters.

122
00:09:12,780 --> 00:09:16,200
So app name followed by the model name.

123
00:09:16,740 --> 00:09:19,080
That's the name convention here.

124
00:09:19,650 --> 00:09:20,790
I'm closing that.

125
00:09:20,790 --> 00:09:28,320
And yeah, that's about creating the admin interface and adding some data to the tables through the

126
00:09:28,320 --> 00:09:29,220
admin interface.

127
00:09:29,220 --> 00:09:34,680
Now we're ready to display those data to the front end for our users.

128
00:09:34,680 --> 00:09:36,290
So let's do that in the next videos.

129
00:09:36,300 --> 00:09:36,810
Thanks.

