WEBVTT 00:00.120 --> 00:01.920 Hello everyone and welcome back. 00:01.980 --> 00:07.020 In this lesson we are going to be talking about putting nation in January's framework by June Asian 00:07.110 --> 00:12.810 allows us to group the results provided by Yahoo API is least views are there to make it easier for 00:12.810 --> 00:15.360 users and clients to retrieve our data. 00:15.720 --> 00:21.920 Let's code similarly to what we've seen in the previous lectures about the permission system. 00:21.970 --> 00:30.030 This framework allows us to set the admission policy for our project on our parent view basis or globally 00:30.330 --> 00:32.670 within the settings that by file. 00:32.670 --> 00:34.860 Same as with the permission system. 00:34.860 --> 00:40.200 This great package offers us different classes that we can implement to set a different Beijing Asian 00:40.200 --> 00:42.000 style according to our needs. 00:42.000 --> 00:48.480 For example we've got the page number of Beijing Asian which is one of the most common ones where we 00:48.480 --> 00:55.290 need to pass a health parameter in this case set to page with the value of the page that we're looking 00:55.290 --> 00:55.750 for. 00:55.830 --> 01:01.500 And the really cool thing about the page number of Beijing Asian class is that the Jason response is 01:01.500 --> 01:08.940 going to automatically contain a link to next and previous page in our budget a To Do list. 01:08.940 --> 01:14.010 We also don't clearly get the results for the specific page right below. 01:14.300 --> 01:20.760 And as you can see sitting there pudgy nation class globally is as easy as it was to set the permissions 01:20.760 --> 01:21.720 classes. 01:21.900 --> 01:26.630 And in this lecture we're going to make an example using their page number. 01:26.740 --> 01:29.640 So I'm going to copy these codes right here. 01:29.640 --> 01:32.630 Let's go back to the settings that they file here. 01:32.820 --> 01:34.490 Just paste this code. 01:34.950 --> 01:40.540 So we've got the default bunch nation class and it's the framework the Beijing nation that page no education 01:40.890 --> 01:42.320 and in page size. 01:42.400 --> 01:44.850 Let's now just use three. 01:45.030 --> 01:51.490 Which is kind of suboptimal in a real case scenario but it's perfect for a use case. 01:51.510 --> 02:01.040 So I'm going to restart the development server like so let's go back to CRO and you see at a moment 02:01.310 --> 02:05.360 I mean I get requests for the e-books least end point. 02:05.390 --> 02:09.120 And as you can see about it a couple of instances. 02:09.410 --> 02:15.950 And considering that I made these get request before setting in that Virginia shown policy globally 02:16.400 --> 02:20.820 I get all this of any books that are at the moment stored in a database. 02:20.900 --> 02:27.110 So let's not make another get request to the same end point and you see it now I only get the first 02:27.200 --> 02:28.810 three instances. 02:28.880 --> 02:37.000 But as you can see I also get count which tells me how many records are there in these specific query 02:37.010 --> 02:37.680 set. 02:37.760 --> 02:46.130 I get a link to the next page and the previous is said to know so little make a get request to Page 02:46.130 --> 02:56.310 Number two we get records for 2 6 and this time we also get you see the previews and point link. 02:56.320 --> 02:59.760 Let's go to the third and final one. 02:59.860 --> 03:05.450 Now next is set to know how we get the previous end point. 03:05.560 --> 03:06.110 Perfect. 03:07.060 --> 03:14.110 So this you see gets incredibly useful especially for out front end clients because of these very useful 03:14.140 --> 03:16.780 next and previous parameters. 03:17.020 --> 03:22.930 And so same as for the permissions system we've defined in the previous lectures in real world use case 03:22.930 --> 03:29.240 scenarios you might need to define the budget Nation policy on a per view basis. 03:29.320 --> 03:39.850 So let's go back to visual studio code and I'm not going to create a new file budget Asia leaving the 03:40.090 --> 03:41.960 EPA folder. 03:41.980 --> 03:43.870 So first of all let's import. 03:43.870 --> 03:52.950 Page number pudgy nation so front rest framework dot budget nation import page number Polynesia. 03:53.170 --> 03:59.980 And so here I can now subclass page number budget ratio to create my own custom class. 04:00.520 --> 04:07.840 So class maybe we can just call it small said Petty nation which is going to extend clearly. 04:07.900 --> 04:10.010 Page number page nation. 04:10.020 --> 04:13.870 And here I can define page size equals. 04:14.200 --> 04:16.640 Let's just use three once again. 04:16.720 --> 04:25.520 So I'm going to comment this out like so I can now import the class. 04:25.520 --> 04:28.100 So you're from. 04:28.260 --> 04:33.870 You moved the TBI with nation import small set bunch nation. 04:34.070 --> 04:39.830 And once again because of how awesome the concrete view glasses are. 04:40.130 --> 04:45.420 I can define an attribute designation plus equals. 04:45.530 --> 04:50.280 Yeah I can just pass a small set pudgy nation like so. 04:50.720 --> 04:57.520 So let's restart our development server once again perfect and let's go back to Chrome. 04:57.520 --> 05:03.410 Remember we've just commented this dictionary of settings right here. 05:03.860 --> 05:11.060 Let's make another request and you see nevertheless we get three pages perfect before finishing the 05:11.060 --> 05:15.270 last one that is one important thing that we must address. 05:15.330 --> 05:17.570 See if you open up the terminal. 05:18.260 --> 05:25.670 Once again we get this message from Django framework not that object the warn me but the nation may 05:25.670 --> 05:27.590 yield inconsistent results. 05:27.620 --> 05:33.110 We've had an ordered object list class e-books dot models dot e-book waste. 05:33.500 --> 05:43.150 So basically we need to actually order at quiet he said if we want to prevent potential errors and luckily 05:43.150 --> 05:45.030 this is extremely easy to do. 05:45.040 --> 05:50.580 As you might know so you're just going to add order by. 05:51.430 --> 05:51.660 Yeah. 05:51.670 --> 05:59.050 We passed the parameter we want to order the list by for example negative I.D. So we get the last added 05:59.050 --> 06:00.450 records first. 06:00.560 --> 06:03.190 Let's restart a server. 06:05.070 --> 06:05.990 Thanks so perfect. 06:06.000 --> 06:07.240 Let's go back to Cairo. 06:07.410 --> 06:14.920 Let's make another get request Hey you see now we get the last e-books first and clearly if you prefer 06:14.920 --> 06:23.100 it the other way around you can just remove the dash into minus let's restart the development server 06:23.110 --> 06:34.040 once again going back to Chrome and other goods request and it is 0 to 1 is back on top of the list. 06:34.040 --> 06:34.290 Okay. 06:34.310 --> 06:37.920 So that was it for this lecture about education in Django framework. 06:37.940 --> 06:39.140 See you in the next election. 06:39.160 --> 06:43.250 What are we going to discuss their competency assessment project for this section.