WEBVTT

00:01.530 --> 00:05.390
Okay, let's try to test our application a little bit.

00:05.400 --> 00:10.560
So what we will need to do is let's try to create some records in our database.

00:10.560 --> 00:17.970
So I will pick a post method, which is for creating new records, and then we'll need to go to the

00:17.970 --> 00:20.640
body and I will do form data.

00:20.640 --> 00:28.710
So basically what we need to send to the movies, if I will try to send it now you can see title and

00:28.710 --> 00:37.830
description is this is required because we can't just post anything with we can't post a title without

00:37.830 --> 00:38.910
the description.

00:39.810 --> 00:45.360
So let's create a movie called Titanic.

00:47.690 --> 00:48.470
Uh, sorry.

00:48.770 --> 00:50.870
We need to do a title.

00:53.250 --> 00:54.090
Titanic.

00:58.420 --> 00:59.620
And description.

01:01.450 --> 01:04.780
Romantic movie.

01:08.340 --> 01:09.480
And something.

01:09.480 --> 01:11.160
It doesn't really matter what we are doing.

01:11.160 --> 01:16.230
This is a kind of mock up data now, so let's try to send it now.

01:17.100 --> 01:17.760
We'll send it.

01:17.760 --> 01:21.210
And you can see here the record has been created.

01:21.210 --> 01:24.180
So if I will change the post to get now.

01:25.880 --> 01:33.770
I have one record in the database and let's try to create a second one just to have something to work

01:33.770 --> 01:34.190
with.

01:34.190 --> 01:38.600
And then we'll have, let's say, a water and then description.

01:40.210 --> 01:44.950
Science fiction movie, which blew guys.

01:44.980 --> 01:45.820
Whatever.

01:46.390 --> 01:50.320
So we have title and description saved.

01:50.350 --> 01:56.560
Now, if we go back to get we expecting two records and in fact we have two records.

01:56.560 --> 02:01.090
So our post is working and then our get is working.

02:01.090 --> 02:07.750
Let's try our put put is for changing the database.

02:07.750 --> 02:09.900
So changing the records we have.

02:09.910 --> 02:17.170
So let's say we have our Titanic here and this is ID one.

02:17.170 --> 02:25.390
So if I will pass ID in the URL at the end one and then slash and I will use put method, whatever I

02:25.390 --> 02:27.820
will send here, it will be updated.

02:27.820 --> 02:30.100
So let's say romantic movie.

02:30.100 --> 02:38.020
I will just update the description just to be romantic movie without that and something.

02:38.020 --> 02:46.210
So I will send it now and you can see the result is updated if I will go get all movies.

02:47.890 --> 02:49.140
I have updated.

02:49.150 --> 02:51.250
So this is working fine.

02:51.250 --> 03:04.960
Let's create a third one to remove and I will create new records now for our purpose to remove it.

03:04.960 --> 03:08.860
So I have Titanic and Avatar that will that are valid records.

03:08.860 --> 03:11.230
But let's say Titanic for remove.

03:11.230 --> 03:12.880
I need to remove this one.

03:12.880 --> 03:20.350
So what I can do is we know that ID of this item is three, so we'll pass three here and then I will

03:20.350 --> 03:25.210
pick a method delete here and then I will send it.

03:25.360 --> 03:26.980
So that's been removed.

03:27.010 --> 03:32.350
I don't see anything in the output here because we just removed the database, so there is nothing to

03:32.350 --> 03:37.150
output and then if I will go get for the all movies.

03:37.150 --> 03:44.230
So movies slash and nothing else, you can see we're back to having two records in our database.

03:44.230 --> 03:49.490
So that's kind of proving that our application is working with the movies.

03:49.490 --> 03:52.910
So what can we do with the ratings now?

03:52.910 --> 03:56.360
So if I go ratings like that.

03:57.140 --> 04:01.850
There is no ratings now, so let's try to create a new rating.

04:01.850 --> 04:11.450
So I will try to post rating and let's say I will do stars and I will try to send, let's say, three

04:11.450 --> 04:12.230
stars.

04:12.470 --> 04:16.580
I will add them for for the moment, I will just remove the description here.

04:16.580 --> 04:18.590
And we are trying to send the stars.

04:18.590 --> 04:20.780
Three So what will happen here?

04:21.050 --> 04:28.010
User and movie is required so I can do movie.

04:28.130 --> 04:36.950
We remember from the previous if I will go movies here that will open a new tab and let's send a use

04:36.950 --> 04:37.940
movies here.

04:37.940 --> 04:40.760
So we have ID one and ID two.

04:40.760 --> 04:43.070
Let's create a.

04:44.360 --> 04:46.460
Movie one.

04:46.460 --> 04:51.020
We need to pass ID for that movie and then user.

04:51.020 --> 04:53.510
So what is actually our user?

04:53.510 --> 05:02.840
What we can do is if I go here to the admin and we will I will show you later on how we can actually

05:02.840 --> 05:07.040
get the data for the login user when we will have authentication.

05:07.040 --> 05:13.130
But if at the moment, if we go to the users here and I will click on the Christian, you can see here

05:13.130 --> 05:21.950
user one change URL that means this is the ID of that user and in fact it is the first user in the database

05:21.950 --> 05:27.020
because we've created that one so we can be sure the ID is one.

05:27.170 --> 05:32.030
So basically what we are doing here is we are trying to create a rating.

05:32.180 --> 05:41.660
We are trying to create a rating with a stars three stars for Movie one, which is our Titanic, and

05:41.660 --> 05:45.390
we are using our user, which is also one.

05:45.390 --> 05:47.460
So let's try to do this now.

05:48.420 --> 05:51.930
And you can see here rating that's ID of the rating.

05:51.930 --> 05:56.190
And then we have three stars for this user and for this movie.

05:56.190 --> 06:02.760
So if I will try to create a new one and The Post is creating new records, so let's say I would like

06:02.760 --> 06:05.880
to change it for four and I will send it.

06:05.880 --> 06:13.470
Now, what will happen is the field user movie must be a unique set and this is what I will.

06:13.470 --> 06:15.900
I told you about it when we had it.

06:16.860 --> 06:21.600
This models unique together here so.

06:22.580 --> 06:30.680
What we are trying to do here is we are trying to create a new record, new rating with the movie and

06:30.680 --> 06:35.510
user that are the same that already exist in our database.

06:35.540 --> 06:41.150
We have our rating for this movie and we have a rating for this user already.

06:41.150 --> 06:42.890
So that will throw an error.

06:42.890 --> 06:49.550
And the reason for this is that unique together, this is form you uniqueness the user and movie.

06:49.580 --> 06:52.610
We cannot have the same one in the database.

06:55.360 --> 06:58.270
But we could use method put.

06:59.000 --> 07:00.380
If I will put it now.

07:02.280 --> 07:12.120
And you can see but is not allowed here because we haven't specified what to do with the put yet.

07:12.150 --> 07:13.710
That's unique together.

07:13.710 --> 07:22.380
Also, it's kind of changing the way we can use our application and we will create actually our own

07:22.770 --> 07:27.900
method later on and we can do all the validation and all our logic.

07:27.900 --> 07:33.120
We can have it in there, but at the moment we can see this is not available.

07:33.300 --> 07:37.890
Okay, so let's try to create a new one.

07:37.890 --> 07:44.670
So I will do the post, but instead of the movie one that we already had our rating on, let's create

07:44.670 --> 07:46.200
a new movie.

07:46.200 --> 07:51.960
I mean create new ratings for a new movie, which is this movie here, Avatar.

07:51.960 --> 07:55.440
And let's try to create a ten stars.

07:58.280 --> 08:03.530
And then you can see ensure the value is less than or equal five.

08:03.560 --> 08:06.590
So if I will try to do zero.

08:08.290 --> 08:11.350
Ensure this value is greater or equal to one.

08:11.350 --> 08:13.930
And the reason we see that.

08:15.800 --> 08:22.340
Message is this validators we have here minimum value and the maximum value.

08:22.340 --> 08:29.600
So you can see here when we write this, this maybe had no sense, but now when we start using our application

08:29.600 --> 08:40.370
and we start to pass some values that won't fit our database, then we can see some very useful information

08:40.370 --> 08:40.820
here.

08:40.820 --> 08:45.080
And actually this will prevent us from from passing this.

08:45.080 --> 08:52.460
And in the same way, if I will try to pass any string here, you can see a valid integer is required.

08:52.460 --> 08:56.180
So Django is doing that, that validation for us.

08:56.210 --> 09:03.080
We decided that this field is integer, so it will validate basically on the type.

09:03.080 --> 09:07.430
So integer only will be accepted, not the strings like here.

09:07.430 --> 09:13.670
And also we need to pass a correct number so we accept everything from 1 to 5.

09:13.700 --> 09:19.860
But if we will pass something outside of that range, then it won't be accepted because we told the

09:19.860 --> 09:23.250
validators to validate our input.

09:23.250 --> 09:26.100
So basically that's how it works.

09:26.160 --> 09:29.430
We have a lot of things to do here.

09:29.430 --> 09:37.740
So what we also need to do, we need to allow users to log in, retrieve the users from the database,

09:37.740 --> 09:41.370
and that user can be used for passing the ratings.

09:41.370 --> 09:49.140
Also, we need to create our own method for having the ratings, and in this way we can actually disable

09:49.170 --> 09:54.870
built in and just focus for, put and post our own.

09:54.900 --> 10:03.300
And also we need to create a few more serializers and having some build methods to put something more

10:03.300 --> 10:04.830
in the movies.

10:04.860 --> 10:11.760
At the moment we don't display a serializer, we don't display any information about the ratings here,

10:11.760 --> 10:14.730
but we could possibly do that.

10:14.850 --> 10:17.910
So we will do that in the next videos.
