WEBVTT 00:00.090 --> 00:05.640 Hello everyone and welcome to Django framework level to come to this assessment solution. 00:05.640 --> 00:11.650 In this lesson we're going to build together one of the possible solutions for the project assigned 00:11.700 --> 00:18.690 the quotes API project and this always I remember you did you can download all the code and the slides 00:18.750 --> 00:21.660 used in each section of the course. 00:21.810 --> 00:28.200 From the first lesson of every section and you will also find the links to the appropriate gate rapidly 00:28.440 --> 00:30.030 from the same lesson. 00:30.150 --> 00:37.890 So let's get started as you can see I'm currently weaving that Django framework level to fall there 00:38.180 --> 00:43.630 where we've been developing so far during this section of the course. 00:43.760 --> 00:48.980 As you can see I've currently activated the same to our environment used in this section. 00:49.040 --> 00:56.730 Therefore I can just give the command Django the main start project to create the new project that we're 00:56.760 --> 00:57.720 going to develop. 00:57.720 --> 01:02.850 In this lesson I can just call it quotes API. 01:03.500 --> 01:08.230 So a lesson and editing is a beautiful project. 01:08.390 --> 01:16.340 And now that we're here we can also create the main up for project which we can just call quotes so 01:17.030 --> 01:24.170 Python manage notes by start up quotes and so with D. 01:24.260 --> 01:30.040 We are now ready to start developing using these words to your code or the editor of your choice. 01:30.050 --> 01:37.880 So I'm going to open this was your code within the project folder like so and we are invisible to your 01:37.880 --> 01:38.400 code. 01:38.420 --> 01:45.720 We can use the control shift beat combination to select and interpret that for this project and we see 01:45.720 --> 01:51.400 that at a moment of work through your code cannot find the development environment that we want to use. 01:51.450 --> 02:02.970 Therefore as always we can just click on File Preferences Settings workspace settings VM and we're just 02:02.970 --> 02:13.580 going to pass the path to that folder what I have defeated what environment that I want to use 02:16.790 --> 02:26.820 copy like so now clicking right here or just using the control shift B combination you see we are able 02:26.820 --> 02:33.970 to select the beautiful environment for Django framework Level 2 and if any problems occur. 02:33.990 --> 02:40.260 Meaning if for any reason visuals your code can't manage to find the virtual environment any way remember 02:40.260 --> 02:49.020 that you can just edit the settings that Jason File and then just manually select the to an environment 02:49.080 --> 02:50.910 that you want to use. 02:50.910 --> 02:58.460 So let's close the settings file and let's install both the quotes up and Django framework. 02:59.100 --> 03:02.710 So rest framework. 03:04.000 --> 03:15.490 And quotes like so and we can now start developing the project as a list starting from the model stood 03:15.490 --> 03:24.170 by file and we can create class quote models not model. 03:24.600 --> 03:30.100 And as you know these projects the specification required is our quote model to have five different 03:30.100 --> 03:30.850 fields. 03:30.850 --> 03:35.860 Quote author quote body context sourced and created at. 03:35.970 --> 03:46.500 And so knowing this we can't start to develop quoth author equals models not char field with max length 03:47.110 --> 04:01.240 fifty is enough then quote body models not text field then context so a context for our quote models 04:01.520 --> 04:09.340 dot char field with Max Planck so we can specify something like two hundred and forty characters like 04:09.340 --> 04:17.140 a tweet but we can also make these feel optional because oftentimes you might not know the exact context 04:17.200 --> 04:18.430 of a specific quote. 04:18.430 --> 04:29.600 Therefore BLANK EQUALS true then super simple models not char field with max length this time under 04:29.610 --> 04:42.680 twenty characters are enough but blank through and then created at the models not Date Time field we 04:42.680 --> 04:43.590 have output. 04:44.530 --> 04:48.100 Now add equals true. 04:48.250 --> 04:56.860 Now considering that quote body uses a text field in the down the string method we can just return it 04:57.760 --> 04:58.190 self. 04:58.210 --> 05:01.790 Dot quote author instead. 05:01.810 --> 05:02.400 Okay cool. 05:02.440 --> 05:06.090 Now that the model is ready we can open up a new terminal. 05:07.090 --> 05:13.660 Like so the environment gets activated and we can create our migrations. 05:13.690 --> 05:26.950 So by phone manage that by make migrations and then Python manage that by migrate and all the migrations 05:27.160 --> 05:28.510 are applied. 05:28.570 --> 05:37.600 Let's also create a super user so create super user admin 05:41.420 --> 05:47.630 as always we are developing for a simple password is fine but to remember that it's vital to use strong 05:47.660 --> 05:50.400 and effective passwords in production. 05:50.440 --> 05:56.810 Now if we wanted to in a real world scenario you might want to actually register in the quote model 05:57.020 --> 05:59.540 within the admin dot py file. 05:59.540 --> 06:04.160 However considering that disease accompanies accessed Assessment Project for a course that is aimed 06:04.160 --> 06:11.180 at teaching you how to use Django as framework we can just skip the admin dot by file and we can create 06:12.380 --> 06:18.250 an API folder instead where we're now going to create all the API related files. 06:18.320 --> 06:31.560 So first of all views that by then he realizes this by and you URLs dot by. 06:31.640 --> 06:36.720 So let's start off by creating the serialized class for our quote model. 06:36.800 --> 06:48.610 So from that as the framework import utilizes and from quotes dot models import quote. 06:48.770 --> 06:57.690 Therefore we can now define class quote utilize it which extends serialize that's not a model C that 06:57.710 --> 07:11.720 I Z India class matter model equals quote We have fields equals and we can select all the fields of 07:11.720 --> 07:12.560 our model. 07:12.830 --> 07:20.150 And now that we've got are seated I said we got started developing our view classes the project specifications 07:20.210 --> 07:28.460 for these quotes API project that required us to use exclusively genetics concrete to view classes and 07:28.670 --> 07:41.390 therefore what we were going to use from the framework import generics then from quotes not models. 07:41.590 --> 07:49.340 Import quote and from quotes dot API dot serialize US import quote serialize it. 07:49.720 --> 07:55.960 Now we know that we will basically need to create two different end points and in point where we are 07:55.960 --> 08:01.590 going to provide create update and delete capabilities for our quote model. 08:01.600 --> 08:09.790 But we also know that we want to allow only Artemis users to actually use these capabilities and then 08:09.880 --> 08:16.970 we know that anyhow I only most users must be able to retrieve basically the available records budget 08:16.980 --> 08:20.380 dated in groups of 30 quotes each. 08:20.740 --> 08:26.830 So as we've seen so far in Django this framework level tool we can create two different classes one 08:26.830 --> 08:32.710 that is going to use the least create API view concrete view class and then the other is going to use 08:32.710 --> 08:46.570 the retrieve update destroy API view class so classic quote least create API view which extends generics 08:46.660 --> 08:50.690 dot least create API view. 08:50.710 --> 08:58.640 So we need to define a query set to use quote dot objects dot all. 08:58.930 --> 09:06.280 And considering that we know that we want to actually generate the results because we know that we need 09:06.280 --> 09:16.360 to provide them in groups of 30 quotes each because of that we can use order by to prevent any progeny 09:16.390 --> 09:19.130 shown errors as you might remember. 09:19.180 --> 09:28.370 So I'm going to order by negative I.D. meaning last records are going to be shown first then you realize 09:28.370 --> 09:38.470 that class equals code serialized there and we're going to think about permissions later on. 09:38.470 --> 09:48.820 For now let's define class and quote detail API view which as we said extends generics dot retrieve 09:48.910 --> 09:57.460 update destroy API view and he's going to basically use the same attributes that we've used up here 09:57.880 --> 09:59.430 except for the order by. 10:00.580 --> 10:07.650 And we are now ready to define the two end points for our quotes API project. 10:08.200 --> 10:21.730 So first of all from Django dot you or else import path and then from quotes dot API dot views import 10:23.440 --> 10:31.430 quote detail EPA view and quote least create API view. 10:31.510 --> 10:49.270 Now your URL but that equals path quotes which is going to call quote least create VBA view dot as you 10:50.100 --> 11:04.210 name it can said something like quote list and then pass quotes does slash integer primary key like 11:04.360 --> 11:04.740 so. 11:06.220 --> 11:17.000 And you're going to call cause detail API if you dot s view with name equals quote in detail. 11:17.370 --> 11:22.350 We now need to include these two and points from within the EU address. 11:22.350 --> 11:29.100 Note by file of the project itself so include and ear. 11:30.330 --> 11:42.390 As always API include quotes dot API dot you else and we are now ready to start the developments that 11:42.390 --> 11:51.710 are very audited to actually check out everything is performing so we need to set the configuration 11:51.740 --> 12:02.710 at configuration Python Django and everything should be fine we have debt default settings except for 12:02.950 --> 12:06.450 no threading which we need to comment out. 12:06.940 --> 12:12.920 So let's start at development server and entities. 12:12.950 --> 12:22.410 He would if he was fine so let's now open up groan let's go to slash API. 12:22.600 --> 12:31.100 We have two points slash quotes ATP 100 OK and editors. 12:31.180 --> 12:36.820 We've got our age to email form and in theory if we wanted to we could start adding instances. 12:37.090 --> 12:44.850 However we know that for this project we want to only add admin use it to be able to create new instances 12:44.860 --> 12:51.550 basically to use these specific point to create new records in our database. 12:51.580 --> 12:59.150 Therefore let's go back to visual studio code and let's go back here. 13:01.650 --> 13:04.070 We can now create permissions 13:07.000 --> 13:16.280 thought by file and yet we are now going to define R is either in use that or read only class to secure. 13:16.350 --> 13:17.960 I didn't create end point. 13:18.040 --> 13:23.530 So from that is the framework to impart that to me shows. 13:23.680 --> 13:35.380 Class is admin use it or read only the dimensions that is admin user. 13:36.130 --> 13:48.780 And here we need to define s permission and we can grab this code define ease I mean and yeah we can 13:48.780 --> 14:03.150 just return request the method in permissions not safe methods or ease I mean we can now import these 14:03.160 --> 14:05.710 classes we've the view is that pie fire. 14:05.790 --> 14:18.660 So actually up here from quotes dot API dot emissions import is admin use it really don't leave and 14:18.930 --> 14:20.450 we can now use it. 14:20.610 --> 14:21.470 We have our classes. 14:21.490 --> 14:30.280 So permission classes equals is I mean user or athlete only. 14:30.370 --> 14:35.710 And the same thing for the detailed end point. 14:35.890 --> 14:42.420 So that update and delete capabilities are granted exclusively to admin users. 14:42.550 --> 14:52.050 So let's restart our development server OK and let's go back right away to Google Chrome let's make 14:52.050 --> 14:53.420 another get request. 14:53.550 --> 15:00.570 You see that the H the email form has disappeared because now we need to logging as admin users. 15:00.810 --> 15:06.270 We could have included Django as frameworks you URLs file in order to be able to logging directly from 15:06.270 --> 15:07.650 the browser API. 15:08.010 --> 15:18.050 However considering our specific development use case it's perfectly fine to just do like so. 15:18.510 --> 15:25.200 So let's create a couple of instances and I've got a couple of quotes here ready to be used quote body 15:25.260 --> 15:27.810 so many books so little time. 15:27.810 --> 15:45.500 Frank Zappa and as source good reads with double O post and now if we wanted to we could clearly also 15:45.500 --> 15:56.600 update you see the instance and let's create a couple more so at Roma without books is like a body without 15:56.600 --> 15:58.080 a soul. 15:58.580 --> 16:09.280 By Marcus tool use the teacher good reads post then maybe a couple more so whatever the mind of a man 16:09.280 --> 16:19.780 can conceive it can achieve by Napoleon Hill and then I attribute my success to this. 16:19.840 --> 16:23.170 I never gave or took any excuses. 16:23.170 --> 16:33.550 So let's create this new quote instance by Florence Nightingale post. 16:34.340 --> 16:37.010 So I actually don't feel that we need to add any more. 16:37.100 --> 16:44.330 Let's go back to these words to your code because we now need to add a final touch to add quotes API 16:44.570 --> 16:44.990 and that's it. 16:44.990 --> 16:47.090 Badger nation of the results. 16:47.090 --> 16:52.040 We can just define everything globally from within the settings dulled by fire. 16:53.680 --> 16:57.360 And so we're going to pass the rest framework dictionary. 16:57.400 --> 17:05.490 We've page size said to 30 as the projected specifications required and default by Jenny show class 17:05.630 --> 17:10.860 clearly and has the framework not Apache Nation not page number Apogee nation. 17:10.860 --> 17:20.530 So let's save and let's restart one less time our development server let's go back to Chrome let's make 17:20.530 --> 17:21.880 another get request. 17:22.580 --> 17:29.020 You see that now we've got to count for next and previous are said to know because we do not have more 17:29.020 --> 17:36.430 than 30 quotes in our database and we got the list of results of the different Jasons of the different 17:36.430 --> 17:37.320 quotes. 17:37.420 --> 17:38.510 Perfect. 17:38.590 --> 17:38.880 Okay. 17:38.910 --> 17:44.440 So that was it for the solution of their competency assessment project for Django framework level to 17:44.710 --> 17:48.590 the next election is going to be the first lecture of Django this framework. 17:48.610 --> 17:54.610 Level 3 what we're going to introduce all the most advanced concepts related to Django rest framework 17:54.640 --> 17:56.410 and developing API is. 17:56.410 --> 17:57.380 We've Django. 17:57.460 --> 18:01.120 And then as you know we're going to start talking about the front end framework of future. 18:01.120 --> 18:01.550 Yes. 18:01.570 --> 18:08.020 In section 6 getting ready to start developing a full fledged single page application we view. 18:08.040 --> 18:08.430 Yes. 18:08.440 --> 18:12.650 And Django this framework in the last section of the course. 18:12.670 --> 18:15.610 So there are a lot of very interesting topics to discuss. 18:15.610 --> 18:17.020 See you in the next lecture.