WEBVTT 00:00.060 --> 00:03.880 Hello everyone and welcome to these units competence assessment solution. 00:03.900 --> 00:08.360 Remember that you can download all the code for the project from the downloadable resources of this 00:08.360 --> 00:09.630 section. 00:09.660 --> 00:12.720 Let's start by creating a new Django project. 00:12.810 --> 00:18.210 As you can see I'm currently in the Django is framework level one folder and I have activated the same 00:18.210 --> 00:22.740 virtual environment that I've been using so far in this section. 00:22.740 --> 00:32.900 I'm just going to call the project a job board so a Django admin staff project job board. 00:33.150 --> 00:40.350 And within this project I'm now going to create an app the update we're going to use to actually define 00:40.350 --> 00:42.960 models serialize this and so on. 00:42.960 --> 00:52.510 I'm going to call these app jobs so Python manage that by start up jobs. 00:52.830 --> 00:57.010 I can I will be in Visual Studio code within this folder. 00:57.300 --> 01:01.990 So code dot which means open code within this folder. 01:02.970 --> 01:08.820 And if we are in these words to your code the first thing that I want to do is to choose a python interpreter 01:08.820 --> 01:09.660 for the project. 01:09.690 --> 01:14.240 So control shift B select interpreter. 01:14.240 --> 01:19.500 In this we can see if he's run us through your code detected automatically the same virtual environment 01:19.560 --> 01:20.630 that we've used. 01:20.760 --> 01:23.200 Therefore I can just click on this one. 01:23.490 --> 01:28.860 And of course a Versa your code for that is being created with the same things that the GS file which 01:28.860 --> 01:31.690 points to the current Python path. 01:31.710 --> 01:37.520 So now that the machine is set up the first thing that we want to do is to go ahead and install John 01:37.510 --> 01:40.090 Kerry's framework and the jobs application. 01:40.110 --> 01:42.470 We've been there installed apps a folder. 01:42.960 --> 01:55.460 So here I'm going to add the rest framework like so many jobs I can now go ahead and start writing the 01:55.460 --> 01:57.290 model for our app. 01:57.410 --> 02:03.500 The specifics of this project requires us to write down only one modest job offer. 02:03.590 --> 02:12.680 So right below I'm going to write the class job offer which is going to win everything from models that 02:12.680 --> 02:14.400 model of course. 02:14.400 --> 02:19.250 And now there are a couple of specific fields that we need to add to our model. 02:19.400 --> 02:28.400 So first of all company name which is going to be char field so mothers thought the char field with 02:28.400 --> 02:30.160 Max linked. 02:30.410 --> 02:33.580 We can set up something like 50. 02:33.650 --> 02:42.870 We're going to have company email which is going to be clearly e-mail field then we're going to have 02:42.960 --> 02:45.600 a job title char field. 02:45.600 --> 02:54.430 So job title and maybe this time Max length can be said to 60. 02:54.540 --> 03:10.110 Then we have a job description model dot text field then salary models dot positive integer field that 03:10.110 --> 03:14.550 we need to add Siri which is going to be char field. 03:14.930 --> 03:22.120 I'm just going to copy this code and we can actually set a max length of thirty five. 03:22.240 --> 03:36.370 It's more than enough for chafing for state do we need the time stamp field created at more than a start 03:36.460 --> 03:38.310 date field. 03:38.410 --> 03:46.810 We've outa now ad through so that this field can be managed automatically by January's framework on 03:46.810 --> 03:59.060 our behalf and then a boolean flag available equals false start boolean field with default equals true. 03:59.210 --> 04:07.050 We now have to define the under string as always so self and maybe you can just return the company name. 04:07.060 --> 04:11.930 So return self-taught company name. 04:11.930 --> 04:13.110 Perfect. 04:13.490 --> 04:20.850 We can now open up a terminal in order to create and apply their migrations to our database. 04:20.870 --> 04:28.670 So Python managed that by make migrations create than job offer. 04:29.200 --> 04:35.280 And now Python managed not by migrate. 04:35.510 --> 04:38.550 And yet we see all the migrations gating applied. 04:38.600 --> 04:40.030 We cannot create the super user. 04:40.040 --> 04:47.900 So Python managed not by create super user and mean 04:51.140 --> 04:51.640 OK. 04:51.670 --> 04:52.330 Perfect. 04:52.330 --> 04:56.140 We can now add our model to the I mean that by fire. 04:56.650 --> 05:02.730 So from jobs models import job it. 05:03.070 --> 05:05.070 I'd been outside the register 05:07.860 --> 05:09.660 jump off it. 05:09.800 --> 05:14.710 We can now run our development server which we actually need to set up. 05:14.720 --> 05:26.050 So add configuration and then Python Django I'm going to comment out no threading like so because I'm 05:26.050 --> 05:27.610 using Chrome. 05:27.760 --> 05:32.020 We can now go ahead and actually launch of development server 05:36.150 --> 05:39.440 and we can now create some instances from admin. 05:40.050 --> 05:55.960 So I'm going to go through slash admin me like so so add in new job offer company name Super Corp and 05:56.180 --> 06:07.950 maybe company email jobs at super Corp dot com job title junior developer job description just generic 06:08.790 --> 06:20.960 description salary we can start off by sixty thousand dollars CDM maybe you can set Milan state Italy. 06:21.600 --> 06:24.750 So let's go ahead and save. 06:24.750 --> 06:28.470 Perfect the job offer super corp was added successfully. 06:28.770 --> 06:32.010 So let's go back to these words with your code. 06:32.100 --> 06:36.150 Let's start creating the API code. 06:36.360 --> 06:42.900 So I'm going to create a new folder weaving the jobs book which I'm going to call API and weaving this 06:42.900 --> 06:52.420 fall that I'm going to create three files serialized there's the two by then I'm going to create fuse 06:52.460 --> 06:57.220 that by file and you'll find your address. 06:57.240 --> 06:57.770 By. 06:58.390 --> 07:03.800 So the first piece of code that we want to write for right API is the serialized reckless. 07:04.030 --> 07:17.170 So from rest framework import lasers from jobs not models import and job offer. 07:17.230 --> 07:23.080 And personally I'm going to use the model serialize that class which as we've seen in great detail is 07:23.080 --> 07:25.730 perfect for these kind of tasks. 07:25.810 --> 07:34.820 So class job offer sterilizer supervisors that model civilization. 07:35.290 --> 07:46.780 Yeah I'm going to define class Meta model equals job offer and fields all the fields we can now create 07:46.810 --> 07:47.440 the views. 07:47.860 --> 07:54.130 And in this particular case I'm going to use the API view class I'm going to make a couple of imports 07:54.610 --> 08:06.930 from this framework that generics import get the object of 4 or four then Trump rest framework that 08:06.940 --> 08:20.890 response import response from risk framework that views import API view and from the rest framework 08:21.550 --> 08:23.990 import studies. 08:24.000 --> 08:30.010 And as a matter of fact maybe we could even displace this one on top like so. 08:30.250 --> 08:35.140 So we now need to import the job of our model and the job offer serialize it a class. 08:35.170 --> 08:51.520 So from jobs that models import job offer jobs that API that Syrian realizes import job offer sterilizer 08:52.060 --> 08:57.610 we're now ready to start writing our own API views and as a matter of fact they're going to be very 08:57.610 --> 09:02.020 similar to the one we've written for the news API project. 09:02.020 --> 09:08.050 Therefore I'm just going to copy the code written for the previous project and then I'm going to adapted 09:08.080 --> 09:09.880 for our current use case. 09:10.270 --> 09:18.130 So going to take it remember that there is nothing bad in and not having to reinvent the wheel all the 09:18.130 --> 09:23.850 time especially if you're the one who has written the code and you know perfectly well how it works. 09:23.860 --> 09:30.860 So I'm just going to adapt it so we can use the search or replace functionality. 09:31.040 --> 09:37.690 I'm going to replace with a job offer I'm going to look for article like so and then we can just hit 09:37.690 --> 09:48.780 enter and confirm the replacement and I can maybe just tweak the code a little bit like Jobs feels that 09:48.840 --> 09:56.220 we've active through is actually perfect for our code even though we need to change it we've available 09:56.370 --> 09:58.070 so available through. 09:58.710 --> 10:01.830 We now need to tweak the code a bit more. 10:01.830 --> 10:07.590 So here you can change these two job and you need to return it. 10:07.590 --> 10:17.400 And then for the sake of consistency in the get method one to put method and ended it its methods. 10:18.690 --> 10:21.120 So it seems like everything is just fine. 10:21.390 --> 10:26.070 Let's reload our development server and let's implement the euro. 10:26.070 --> 10:27.470 Start by file. 10:27.540 --> 10:33.430 So first of all from Django not your else import path. 10:34.040 --> 10:45.720 And then out of use from jobs dot API dot views import job offer detail API view. 10:45.750 --> 10:56.760 So you can copy the name from your and also job off at least create API view perfect. 10:57.120 --> 11:01.570 Let's now define the U.S. real partners list. 11:02.240 --> 11:04.010 So first of all path. 11:04.660 --> 11:07.650 Where we can just set it to jobs. 11:09.450 --> 11:20.500 Which is going to call job offer at least create API view with name equals jobs or rather job listings. 11:20.990 --> 11:26.180 We need to call as view so that our class can actually be used. 11:26.440 --> 11:29.990 Then we're going to have a second endpoint clearly. 11:30.080 --> 11:35.970 So thanks so what's going to be jobs. 11:36.180 --> 11:44.970 And an integer primary key is going to call job offer a detailed EPA view dot as view and the name is 11:44.970 --> 11:48.090 going to be job detail. 11:48.300 --> 11:52.550 We now need to connect the you s not by file to date. 11:52.660 --> 11:56.110 You have to start by file that is being automatically created. 11:56.110 --> 11:59.200 Basically the main you are installed by file. 11:59.200 --> 12:14.440 So we need to import include and right here we can't Dan defined path API include jobs not API not you 12:14.600 --> 12:15.610 or else. 12:15.610 --> 12:18.660 So let's restart our development server once again. 12:19.890 --> 12:21.230 Perfect. 12:21.270 --> 12:25.600 Let's now go back to Chrome so we can go and view side. 12:25.620 --> 12:35.610 We got our API and find the source slash API slash job so perfect and it is at least we have all the 12:35.610 --> 12:37.970 available job offers. 12:38.010 --> 12:39.420 Let's add some more. 12:39.420 --> 12:41.660 We now want the F1 course. 12:41.710 --> 12:56.580 So I'm going to delete I.D. and created at City London state UK salary sixty five thousand and you can 12:56.580 --> 13:00.200 just set it generic second company. 13:00.240 --> 13:04.970 So jobs at second company dot org. 13:05.330 --> 13:09.230 Maybe position senior developer. 13:09.360 --> 13:16.920 Let's not post our first job offer via API and perfect to a one created and it are the details of these 13:16.980 --> 13:18.840 specific instance. 13:18.900 --> 13:21.800 So let's go back to the main endpoint. 13:22.470 --> 13:23.990 And here they are both of them. 13:24.360 --> 13:28.320 So let's say that this specific position has been taken. 13:28.310 --> 13:35.700 The one with primary key one so I'm going to update the instance to change its boolean flags. 13:35.730 --> 13:43.390 I'm going to use clearly the same Jason I'm going to delete I.D. and create a dead end. 13:43.560 --> 13:51.390 I'm going to switch available that is now going to be false so let's make it put the requester to perfect 13:51.510 --> 13:54.060 the instance as you can see it's been updated. 13:54.060 --> 14:02.060 Let's go back to at least the had we now only see the second one which is still available. 14:02.060 --> 14:07.790 Let's now test once again the second endpoint. 14:07.890 --> 14:10.880 Let's make a delete request this time. 14:10.950 --> 14:13.010 Are you sure you want to delete delete. 14:13.830 --> 14:16.950 And if it is too old for new content everything succeeded. 14:16.950 --> 14:17.510 Perfect. 14:17.850 --> 14:20.300 So that was it for the solution of this project. 14:20.310 --> 14:25.230 See you in the next lecture which is also going to be the first lecture of the new section Django this 14:25.230 --> 14:25.750 framework. 14:25.830 --> 14:26.280 Level 2.