WEBVTT 00:00.090 --> 00:02.480 Hello everyone and welcome back. 00:02.490 --> 00:08.520 In this letter we are going to start developing a user profile based Django project that we are going 00:08.520 --> 00:12.030 to use and customize throughout the whole section. 00:12.060 --> 00:14.910 We will see how to extend the jingles basic user model. 00:14.910 --> 00:21.450 We have a second model that we create allowing us to store further information about our users such 00:21.450 --> 00:24.690 as a user Espanol graphic s.t. and Avatar. 00:24.690 --> 00:29.610 Each user will then be able to write the status messages that will be binding to his profile. 00:29.850 --> 00:32.890 Similarly to what happens in most social networks. 00:33.060 --> 00:37.810 This will also give us the chance to introduce to those of us who do not already know them. 00:37.910 --> 00:45.330 JANGLES signals signals are very powerful because they allow certain senders to notify a set of receivers 00:45.630 --> 00:49.680 that some action is taking place elsewhere in the framework. 00:49.680 --> 00:56.550 In our user profile API project we are going to use the signals to automatically create and bind profiles 00:56.580 --> 01:00.500 instance to a user object as soon as a new one is created. 01:00.510 --> 01:08.700 So let's get started as you can see I've created a new folder called Django as framework Level 3 and 01:08.700 --> 01:15.240 I've also created a new virtual environment that I have already activated and we in this environment. 01:15.270 --> 01:22.560 I've installed Django Django framework and pillow which we are going to need to manage our profiles 01:22.640 --> 01:23.580 about us. 01:23.760 --> 01:31.110 So let's create a profiles API project Django add me. 01:31.590 --> 01:43.180 Start Project profiles API and entities so change directory profile CPI. 01:43.980 --> 01:49.900 Let's create the main app for our project which we can just call profiles. 01:49.920 --> 01:59.910 So start up profiles and this always we can now open these rules to the code within the projects folder 02:01.390 --> 02:10.850 we can now perform all the routine operations so select interpreter and it it is I can use Django this 02:10.850 --> 02:19.460 framework a Level 3 V12 environment and if we have other settings that Jason fine let's now install 02:19.550 --> 02:23.060 both their profiles up and Django framework. 02:23.600 --> 02:26.630 So rest framework 02:29.450 --> 02:30.100 profiles. 02:30.950 --> 02:37.520 And considering that we are now in the settings not by file and we we're going to need to actually use 02:37.700 --> 02:44.880 images in this project we can set media you l and media route right here. 02:44.960 --> 02:56.750 So media you address all media and media root you can just call it uploads. 02:56.750 --> 02:58.060 Perfect. 02:58.130 --> 03:06.110 And actually we can also said that you are real but there is to use in order for our development server 03:06.140 --> 03:09.340 to provide and serve all of the media files. 03:09.350 --> 03:16.880 So this is the code the standard code of course that we need to perform such action and we can now go 03:16.880 --> 03:20.440 ahead and start developing our profiles up. 03:20.510 --> 03:24.770 So let's start by creating the models that we need. 03:24.770 --> 03:31.850 And so specifically we are going to create two models a profile model and a profile start to model. 03:32.390 --> 03:36.560 So far we've been using the User model for all sorts of different things. 03:36.590 --> 03:39.860 First of all and most importantly to authenticate our users. 03:39.860 --> 03:45.170 But we've also connected it to other mothers such as for example the review model in debug CPA project 03:45.450 --> 03:52.250 and so now we are going to explore one of the possible ways that we can extend Django as user model 03:52.340 --> 03:57.170 by connecting it to another model profile which we're also going to create. 03:57.170 --> 04:02.390 This would allow us to store further information about our users such as for example a biography and 04:02.390 --> 04:03.650 how about that. 04:03.830 --> 04:10.300 And we're also going to bind these new profile more than to the profile start to model so that we're 04:10.340 --> 04:17.750 going to use Django as user model only to authenticate users weaving our system enabling this way a 04:17.750 --> 04:22.220 better separation of concerns between the different parts of our project. 04:22.220 --> 04:27.560 This is not the only way that you can extend the Django as user model and as a matter of fact we're 04:27.590 --> 04:31.200 going to exploit it that way to do so later on during the course. 04:31.220 --> 04:42.740 So let's import the User model first from Django dot country dot off dot models import user and now 04:43.250 --> 04:53.080 class profile which is going to extend more not model as any other normal model will do. 04:53.210 --> 04:57.960 So yeah first of all we need to make that connection between the profit model and the User model. 04:57.980 --> 05:11.030 This way user equals model is not one to one field referencing user weave on the ether models dot cascade 05:11.510 --> 05:17.870 and the one to one field the relationship is a perfect fit for these specific tasks because we want 05:17.960 --> 05:25.270 each user to only have access to one profile then we're going to have if you're going to fee model is 05:25.270 --> 05:37.430 not shot field with max length two hundred and forty characters like through we've clearly of course 05:37.430 --> 05:47.840 the capital T then we're going to have a Citi Field SATTERFIELD We have max length of 30 characters 05:48.320 --> 05:59.180 and we're going to have an about that field so models not image field we both know through and blank 06:00.590 --> 06:10.010 through now we know that the user model clearly extends the abstract user model which in itself contains 06:10.070 --> 06:17.720 a couple of really useful fields such as for example User Name First Name Last Name Email is stuff and 06:17.720 --> 06:25.890 so on and so in order for us to properly define a good string representation for our profile more than 06:26.360 --> 06:32.930 we can just use that user name a field that is associated with the use it that would link in their profile 06:32.930 --> 06:33.220 to. 06:33.590 --> 06:47.300 So Def then the string good return self note to use it let's use that name and let's now define their 06:47.300 --> 06:55.290 profile status model so class profile status models not more then. 06:55.700 --> 07:05.000 And the profile status model as for different fields first of all user profile field which we need to 07:05.000 --> 07:15.560 connect using a foreign key field to date profile model we've owned delete models don't cascade is always 07:16.340 --> 07:17.870 there we're going to start those 07:20.480 --> 07:30.190 content equals models Dot charter field with max length equals two hundred and forty characters and 07:30.270 --> 07:34.070 we can add created at equals. 07:34.260 --> 07:35.370 Models Dot. 07:35.370 --> 07:38.740 Date Time field with out. 07:39.690 --> 07:49.420 Now add equals through and and updated at field. 07:49.510 --> 07:50.770 We have our toll now. 07:52.280 --> 07:55.840 Through let us now define the dangerous thinning method. 07:56.610 --> 07:57.600 Yes. 07:57.710 --> 08:00.100 Yeah that self. 08:00.300 --> 08:04.560 We can just as well return the profile that is associated with the profile start. 08:04.580 --> 08:05.620 So. 08:05.890 --> 08:11.090 Third string version of self-taught user profile. 08:11.120 --> 08:12.230 Perfect. 08:12.230 --> 08:16.240 We can now register the two models in the admin dot by fire. 08:16.490 --> 08:25.790 So from profiles to models import profile and profile here. 08:26.020 --> 08:33.610 Add me on site to register profile and safety. 08:34.740 --> 08:41.100 For profile starts now regarding the admin site registration of the different models that is one thing 08:41.100 --> 08:47.070 to keep into consideration and that's is the fact that as you probably know in the admin side Jenga 08:47.070 --> 08:53.010 is going to set the plural version of the name of the model that you registered in and with the international 08:53.010 --> 08:58.210 localization using the English language the plural version of profile status might be. 08:58.210 --> 09:03.350 Profiles start to cease but Django by default only adds an s at the end. 09:03.360 --> 09:11.990 Like for example Apple and apples and so we can't specify right here in the model plus meta. 09:12.000 --> 09:15.280 And here we can set variables. 09:16.290 --> 09:20.090 Name Pluto equals. 09:20.100 --> 09:23.340 We can just set it to statuses. 09:23.460 --> 09:24.450 Perfect. 09:24.570 --> 09:26.180 So it's time to give the commands. 09:26.190 --> 09:30.720 Make migrations and migrate as always. 09:30.720 --> 09:33.440 So it is vital to an environment. 09:33.700 --> 09:44.720 Python managed that by make migrations and Python manage that by migrate and let us also create a super 09:44.730 --> 09:45.210 user. 09:45.210 --> 09:51.420 So Python managed by create super user I mean 09:54.580 --> 09:55.500 perfect. 09:55.540 --> 10:00.580 So let's now close this down and let's run out of developments celebrate instead. 10:00.580 --> 10:06.230 So we need as always to briefly set the configuration for our project. 10:06.250 --> 10:14.500 So the configuration Django no threading commented like so. 10:14.500 --> 10:19.300 So let's start the development of our 3D fine. 10:20.180 --> 10:21.220 Perfect. 10:21.270 --> 10:27.290 Like so and so let's open up google chrome okay. 10:27.300 --> 10:28.490 Here we go. 10:28.800 --> 10:34.560 Slash admin going to log in has had me awesome. 10:34.590 --> 10:41.670 And as you can see we got profiles and statuses and of course we got our art to be an E is let's create 10:41.730 --> 10:44.530 a profile instance for that and use it. 10:44.730 --> 10:56.630 So you see user I can just select add me biography I can add site administrator CTE test land and let's 10:56.640 --> 10:58.840 also choose an avatar. 10:58.980 --> 11:05.140 So as you see in this case I've got a red square that we can select to save. 11:05.400 --> 11:08.460 And this is our first profile instance. 11:08.460 --> 11:10.560 And you also got an avatar that we can show.