In the previous video, we alredy create a device models. 2
Now, in this video, we are going to creat a device list menu. This menu will display all of devices from the database. 3
Okay let’s just start. Open the visual studio code. First we need to create a new url. 4
Open the urls.py file inside our app. 5
Here let’s create a new url, let’s say devices. 6
This url will be redirected to devices function inside views. 7
Next, we need to create device function inside views.py. 8
We need to create a variable to save all devices from the database. 9
Let’s use this variable as a context. 10
We will return a template file devices.html, 11
and don’t forget to use the context 12
in the return statement. 13
Last, we need to create a devices.html file. I already upload devices.html file in the resource section. 14
So you can just download it and put the file to the template directory. 15
Okay now we have devices.html in the templates directory. Let’s understand the code here. 16
First we extend from base.html. In the block content, we have a table. 17
We have a looping statement here. We need to change this variable with our context, 18
in this case, the name of our context is all_device. Here we display ip address, hostname, and 19
vendor of each device. 20
Let’s go to the browser, navigate to 127.0.0.1:8000/devices. 21
Here we can see that we have successfully get the list of device from the database. 22
To make sure, let’s create 1 new device in the database. 23
Let’s back to the device list menu, refresh. 24
And here we are ! Now we can see 1 new device that we just created. 25
This is mean that our device list menu is work! 26
This is the end of this video, in the next video, we are going to create a Configure Menu 27
Thankyou for watching and see you on the next video!