WEBVTT 00:00.090 --> 00:03.540 Hello everyone and welcome to dissections project solution. 00:03.570 --> 00:06.950 I remember you did you can download all the code for these projects. 00:06.960 --> 00:13.880 A solution from these sections downloadable resources here on me and from a Gaeta profile address GitHub 00:14.010 --> 00:16.420 cop slash by Mike double zero. 00:16.840 --> 00:22.470 So we are wizards to your code and as you can see there is no file opened in the workbench. 00:22.500 --> 00:25.480 Instead the terminal is up and running. 00:25.680 --> 00:32.850 Django is development server is running and that's because I've been busy adding some instances to our 00:32.850 --> 00:33.680 database. 00:33.690 --> 00:41.100 I've created a couple of new manufacturing instances of I did Lenovo Sony and an inactive manufacturer 00:41.130 --> 00:44.400 that afflict as inactive. 00:44.400 --> 00:50.550 And I've also added some products and that's because for these you need assessment project you were 00:50.550 --> 00:58.410 asked to create two new endpoints for our online store API one to show at least we've all the active 00:58.600 --> 01:01.300 manufacturing instances on our database. 01:01.440 --> 01:07.200 And another one to show all the details of a single manufacturing instance based on a pyramid scheme 01:07.230 --> 01:08.910 passed by the user. 01:08.910 --> 01:10.760 We have products included. 01:10.860 --> 01:16.020 Therefore I've added some records in the database in order for us to have some instances to work with. 01:16.050 --> 01:21.990 We've already mentioned our the two new endpoints that we need to create are going to be very similar 01:22.500 --> 01:25.410 to the one that we've created in the previous lectures. 01:25.410 --> 01:30.450 And as a matter of fact most of the code that we're going to write is going to be very similar to the 01:30.450 --> 01:32.300 one that we've already written. 01:32.400 --> 01:36.300 So let's start by writing The View for our first aid point. 01:36.300 --> 01:41.550 They want to show at least we have all the manufacturing instances that are active in our database. 01:41.550 --> 01:49.890 So I can't go ahead and copy the product list function based view can pass it right here and I'm going 01:49.890 --> 01:52.050 to change the code. 01:52.110 --> 02:02.810 So it's not going to be a product list but manufacturer at least I can copy this one right here right 02:02.810 --> 02:05.710 here and of course here. 02:06.710 --> 02:09.580 And of course the equity set is going to be different. 02:09.680 --> 02:19.030 So I'm going to need manufacturing class is going to be manufacturer not objects that filter with collective 02:21.180 --> 02:22.430 equals true. 02:22.620 --> 02:27.630 Going to delete this comment right here and the one right below. 02:27.870 --> 02:34.750 So we'll getting the query set of all the manufacturing objects that should be flagged as active. 02:34.800 --> 02:42.620 We're then taking the values of all these instances and we're using these values to create a date a 02:42.630 --> 02:49.670 additionally that would feed into the J response class to create a proper Jason response that would 02:49.700 --> 02:52.000 then returning to the client. 02:52.110 --> 02:57.700 So we now need to define a other path meaning we need to define the actual end point. 02:57.750 --> 02:58.310 Right. 02:58.320 --> 03:02.570 To call are manufactured at least in view that we can actually import. 03:02.610 --> 03:09.330 So either I can do something like these can just go a new line. 03:09.730 --> 03:16.630 So even though it's best practice to keep in alphabetical order that is so I can actually bring manufacturing 03:16.630 --> 03:23.420 at least on top and I can do close the tuple like so. 03:23.420 --> 03:31.300 So let's define our End Point I'm going to copy the products and bind right here and it's going to be 03:33.110 --> 03:38.290 manufacturers and the name is going to be manufactured at least. 03:38.570 --> 03:41.390 And who's going to call the manufacturer at least a few. 03:41.570 --> 03:44.780 So let's not create the second view that we need. 03:44.780 --> 03:54.510 We can just go ahead and copy the product detail function code and just as we need for manufactured 03:54.540 --> 03:59.190 at least we also need to modify the code for these functions. 03:59.190 --> 04:08.860 So it's going to be manufactured in detail and I can go ahead and change product to manufacturer. 04:08.930 --> 04:10.460 Same thing here. 04:10.670 --> 04:15.680 We clearly don't need any instance of product but any instance of manufacturer. 04:16.310 --> 04:26.240 And of course we can also we need to change the accept clause regarding the data dictionary we can actually 04:26.240 --> 04:33.320 keep name because as you remember we've got a name field and we've also got to locate your field and 04:33.350 --> 04:44.260 an active field so that I can change this to manufacture the top name that we've got location so location 04:44.260 --> 04:44.830 is going to be 04:47.480 --> 04:54.320 manufactured at that location where manufacture that of course is our instance of manufacturing. 04:55.090 --> 05:02.750 Then we've got active so manufacturer that active boolean flag and we also need to show at least we 05:02.750 --> 05:07.170 have all the products in our database that were made by the same manufacturer. 05:07.730 --> 05:15.410 And because we've linked the two models using products as related name for the inverse relationship 05:15.590 --> 05:21.950 we can now get equity said we've all the related products by using its related name. 05:21.950 --> 05:35.390 So yeah we can do manufacturer products equals I can do something like manufacturer products not or 05:35.990 --> 05:41.610 and we can now do something similar to what we've done right here in the least. 05:41.630 --> 05:45.430 So this is going to be products 05:48.540 --> 05:56.230 and this is going to be at least some of the values of the manufacturer products equates it. 05:56.370 --> 06:05.360 We also need to change the error message so it's going to be manufacturer not found if there is no correlation 06:05.360 --> 06:12.050 between the past primary key and that equals in our database so we can finally link our view to a real 06:12.050 --> 06:18.580 path in order to create a new endpoint so we need to import the view first. 06:19.010 --> 06:29.440 And again following alphabetical order it can do like so then here I can just copy this end point right 06:29.470 --> 06:29.800 here. 06:30.040 --> 06:37.110 So it's going to be manufactured in detail and it's going to trigger manufacture a data function. 06:37.390 --> 06:40.420 And of course the endpoint itself is going to be different. 06:40.450 --> 06:48.140 So are now finally ready to reload our development server and give value endpoints to try. 06:48.140 --> 06:55.530 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 06:55.550 --> 07:01.930 Lesh API and of course every now we've also added two new end. 07:02.030 --> 07:04.640 So let's check manufacturing at least first. 07:04.640 --> 07:13.280 So slash API slash manufacturers slash and entities and Jason response and that is you can see only 07:13.280 --> 07:16.710 shows the manufacturers that would be flagged as active. 07:16.730 --> 07:22.130 So as you can see here on Chrome there is another window that is open and is a window of the home page 07:22.160 --> 07:23.020 of the Web site. 07:23.030 --> 07:24.830 JASON format that dot org. 07:24.860 --> 07:31.280 So as we've said in the previous lectures the file format is really cool because he's both human readable 07:31.370 --> 07:38.060 and very fast for machines to process but it is also clear that it can be a pain to actually get a sense 07:38.060 --> 07:44.720 of all the information that I've shown considering that all day new lies and the tabs get stripped away 07:44.720 --> 07:49.160 in order to make the response as small and therefore fast as possible. 07:49.550 --> 07:54.990 And so when getting a adjusted response as the one shown here you oftentimes want to use a Jason or 07:54.990 --> 07:58.820 for that matter to show its content in a much more pleasant way. 07:59.000 --> 08:04.100 As we've seen the following sections Django this framework also provides this kind of functionality 08:04.340 --> 08:09.690 via the so-called browser bull API which of course we will learn to use. 08:09.710 --> 08:16.190 So let's make another example let's say we want to get all the details of Sony which is a manufacturer 08:16.190 --> 08:18.590 that we've I.D. to as we can see. 08:18.590 --> 08:24.560 So let's go back to the first window and let's make a get request to the end point API manufacturers 08:24.800 --> 08:27.670 to which is its primary key. 08:27.690 --> 08:31.760 Yet we get all the details for these specific instance. 08:31.790 --> 08:33.340 So let's go back to it for a matter. 08:34.160 --> 08:35.960 Let's pass that to Jason. 08:36.050 --> 08:42.770 And as you can see we now get all the details for this Sony's this included deep product leased and 08:42.770 --> 08:48.190 considering that I haven't added any image for neither the Playstation or devalue. 08:48.230 --> 08:50.420 We just get an empty string. 08:50.420 --> 08:55.790 So that was it for the solution of these sections assessment project and this was also the last video 08:55.790 --> 08:57.640 for the way BPI section. 08:57.730 --> 09:03.710 We're now finally ready to start using django rest framework in the next section jingoist framework 09:03.800 --> 09:05.030 level 1 c of that.