Hello everyone and welcome to dissections project solution.
I remember you did you can download all the code for these projects.
A solution from these sections downloadable resources here on me and from a Gaeta profile address GitHub
cop slash by Mike double zero.
So we are wizards to your code and as you can see there is no file opened in the workbench.
Instead the terminal is up and running.
Django is development server is running and that's because I've been busy adding some instances to our
database.
I've created a couple of new manufacturing instances of I did Lenovo Sony and an inactive manufacturer
that afflict as inactive.
And I've also added some products and that's because for these you need assessment project you were
asked to create two new endpoints for our online store API one to show at least we've all the active
manufacturing instances on our database.
And another one to show all the details of a single manufacturing instance based on a pyramid scheme
passed by the user.
We have products included.
Therefore I've added some records in the database in order for us to have some instances to work with.
We've already mentioned our the two new endpoints that we need to create are going to be very similar
to the one that we've created in the previous lectures.
And as a matter of fact most of the code that we're going to write is going to be very similar to the
one that we've already written.
So let's start by writing The View for our first aid point.
They want to show at least we have all the manufacturing instances that are active in our database.
So I can't go ahead and copy the product list function based view can pass it right here and I'm going
to change the code.
So it's not going to be a product list but manufacturer at least I can copy this one right here right
here and of course here.
And of course the equity set is going to be different.
So I'm going to need manufacturing class is going to be manufacturer not objects that filter with collective
equals true.
Going to delete this comment right here and the one right below.
So we'll getting the query set of all the manufacturing objects that should be flagged as active.
We're then taking the values of all these instances and we're using these values to create a date a
additionally that would feed into the J response class to create a proper Jason response that would
then returning to the client.
So we now need to define a other path meaning we need to define the actual end point.
Right.
To call are manufactured at least in view that we can actually import.
So either I can do something like these can just go a new line.
So even though it's best practice to keep in alphabetical order that is so I can actually bring manufacturing
at least on top and I can do close the tuple like so.
So let's define our End Point I'm going to copy the products and bind right here and it's going to be
manufacturers and the name is going to be manufactured at least.
And who's going to call the manufacturer at least a few.
So let's not create the second view that we need.
We can just go ahead and copy the product detail function code and just as we need for manufactured
at least we also need to modify the code for these functions.
So it's going to be manufactured in detail and I can go ahead and change product to manufacturer.
Same thing here.
We clearly don't need any instance of product but any instance of manufacturer.
And of course we can also we need to change the accept clause regarding the data dictionary we can actually
keep name because as you remember we've got a name field and we've also got to locate your field and
an active field so that I can change this to manufacture the top name that we've got location so location
is going to be
manufactured at that location where manufacture that of course is our instance of manufacturing.
Then we've got active so manufacturer that active boolean flag and we also need to show at least we
have all the products in our database that were made by the same manufacturer.
And because we've linked the two models using products as related name for the inverse relationship
we can now get equity said we've all the related products by using its related name.
So yeah we can do manufacturer products equals I can do something like manufacturer products not or
and we can now do something similar to what we've done right here in the least.
So this is going to be products
and this is going to be at least some of the values of the manufacturer products equates it.
We also need to change the error message so it's going to be manufacturer not found if there is no correlation
between the past primary key and that equals in our database so we can finally link our view to a real
path in order to create a new endpoint so we need to import the view first.
And again following alphabetical order it can do like so then here I can just copy this end point right
here.
So it's going to be manufactured in detail and it's going to trigger manufacture a data function.
And of course the endpoint itself is going to be different.
So are now finally ready to reload our development server and give value endpoints to try.
So I'm just going to minimize the terminal and let's go back to Chrome so let's go to a local ost as
Lesh API and of course every now we've also added two new end.
So let's check manufacturing at least first.
So slash API slash manufacturers slash and entities and Jason response and that is you can see only
shows the manufacturers that would be flagged as active.
So as you can see here on Chrome there is another window that is open and is a window of the home page
of the Web site.
JASON format that dot org.
So as we've said in the previous lectures the file format is really cool because he's both human readable
and very fast for machines to process but it is also clear that it can be a pain to actually get a sense
of all the information that I've shown considering that all day new lies and the tabs get stripped away
in order to make the response as small and therefore fast as possible.
And so when getting a adjusted response as the one shown here you oftentimes want to use a Jason or
for that matter to show its content in a much more pleasant way.
As we've seen the following sections Django this framework also provides this kind of functionality
via the so-called browser bull API which of course we will learn to use.
So let's make another example let's say we want to get all the details of Sony which is a manufacturer
that we've I.D. to as we can see.
So let's go back to the first window and let's make a get request to the end point API manufacturers
to which is its primary key.
Yet we get all the details for these specific instance.
So let's go back to it for a matter.
Let's pass that to Jason.
And as you can see we now get all the details for this Sony's this included deep product leased and
considering that I haven't added any image for neither the Playstation or devalue.
We just get an empty string.
So that was it for the solution of these sections assessment project and this was also the last video
for the way BPI section.
We're now finally ready to start using django rest framework in the next section jingoist framework
level 1 c of that.