Hello everyone and welcome back.
In this lesson we are going to be talking about putting nation in January's framework by June Asian
allows us to group the results provided by Yahoo API is least views are there to make it easier for
users and clients to retrieve our data.
Let's code similarly to what we've seen in the previous lectures about the permission system.
This framework allows us to set the admission policy for our project on our parent view basis or globally
within the settings that by file.
Same as with the permission system.
This great package offers us different classes that we can implement to set a different Beijing Asian
style according to our needs.
For example we've got the page number of Beijing Asian which is one of the most common ones where we
need to pass a health parameter in this case set to page with the value of the page that we're looking
for.
And the really cool thing about the page number of Beijing Asian class is that the Jason response is
going to automatically contain a link to next and previous page in our budget a To Do list.
We also don't clearly get the results for the specific page right below.
And as you can see sitting there pudgy nation class globally is as easy as it was to set the permissions
classes.
And in this lecture we're going to make an example using their page number.
So I'm going to copy these codes right here.
Let's go back to the settings that they file here.
Just paste this code.
So we've got the default bunch nation class and it's the framework the Beijing nation that page no education
and in page size.
Let's now just use three.
Which is kind of suboptimal in a real case scenario but it's perfect for a use case.
So I'm going to restart the development server like so let's go back to CRO and you see at a moment
I mean I get requests for the e-books least end point.
And as you can see about it a couple of instances.
And considering that I made these get request before setting in that Virginia shown policy globally
I get all this of any books that are at the moment stored in a database.
So let's not make another get request to the same end point and you see it now I only get the first
three instances.
But as you can see I also get count which tells me how many records are there in these specific query
set.
I get a link to the next page and the previous is said to know so little make a get request to Page
Number two we get records for 2 6 and this time we also get you see the previews and point link.
Let's go to the third and final one.
Now next is set to know how we get the previous end point.
Perfect.
So this you see gets incredibly useful especially for out front end clients because of these very useful
next and previous parameters.
And so same as for the permissions system we've defined in the previous lectures in real world use case
scenarios you might need to define the budget Nation policy on a per view basis.
So let's go back to visual studio code and I'm not going to create a new file budget Asia leaving the
EPA folder.
So first of all let's import.
Page number pudgy nation so front rest framework dot budget nation import page number Polynesia.
And so here I can now subclass page number budget ratio to create my own custom class.
So class maybe we can just call it small said Petty nation which is going to extend clearly.
Page number page nation.
And here I can define page size equals.
Let's just use three once again.
So I'm going to comment this out like so I can now import the class.
So you're from.
You moved the TBI with nation import small set bunch nation.
And once again because of how awesome the concrete view glasses are.
I can define an attribute designation plus equals.
Yeah I can just pass a small set pudgy nation like so.
So let's restart our development server once again perfect and let's go back to Chrome.
Remember we've just commented this dictionary of settings right here.
Let's make another request and you see nevertheless we get three pages perfect before finishing the
last one that is one important thing that we must address.
See if you open up the terminal.
Once again we get this message from Django framework not that object the warn me but the nation may
yield inconsistent results.
We've had an ordered object list class e-books dot models dot e-book waste.
So basically we need to actually order at quiet he said if we want to prevent potential errors and luckily
this is extremely easy to do.
As you might know so you're just going to add order by.
Yeah.
We passed the parameter we want to order the list by for example negative I.D. So we get the last added
records first.
Let's restart a server.
Thanks so perfect.
Let's go back to Cairo.
Let's make another get request Hey you see now we get the last e-books first and clearly if you prefer
it the other way around you can just remove the dash into minus let's restart the development server
once again going back to Chrome and other goods request and it is 0 to 1 is back on top of the list.
Okay.
So that was it for this lecture about education in Django framework.
See you in the next election.
What are we going to discuss their competency assessment project for this section.