Okay, let's try to test our application a little bit.
So what we will need to do is let's try to create some records in our database.
So I will pick a post method, which is for creating new records, and then we'll need to go to the
body and I will do form data.
So basically what we need to send to the movies, if I will try to send it now you can see title and
description is this is required because we can't just post anything with we can't post a title without
the description.
So let's create a movie called Titanic.
Uh, sorry.
We need to do a title.
Titanic.
And description.
Romantic movie.
And something.
It doesn't really matter what we are doing.
This is a kind of mock up data now, so let's try to send it now.
We'll send it.
And you can see here the record has been created.
So if I will change the post to get now.
I have one record in the database and let's try to create a second one just to have something to work
with.
And then we'll have, let's say, a water and then description.
Science fiction movie, which blew guys.
Whatever.
So we have title and description saved.
Now, if we go back to get we expecting two records and in fact we have two records.
So our post is working and then our get is working.
Let's try our put put is for changing the database.
So changing the records we have.
So let's say we have our Titanic here and this is ID one.
So if I will pass ID in the URL at the end one and then slash and I will use put method, whatever I
will send here, it will be updated.
So let's say romantic movie.
I will just update the description just to be romantic movie without that and something.
So I will send it now and you can see the result is updated if I will go get all movies.
I have updated.
So this is working fine.
Let's create a third one to remove and I will create new records now for our purpose to remove it.
So I have Titanic and Avatar that will that are valid records.
But let's say Titanic for remove.
I need to remove this one.
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
pick a method delete here and then I will send it.
So that's been removed.
I don't see anything in the output here because we just removed the database, so there is nothing to
output and then if I will go get for the all movies.
So movies slash and nothing else, you can see we're back to having two records in our database.
So that's kind of proving that our application is working with the movies.
So what can we do with the ratings now?
So if I go ratings like that.
There is no ratings now, so let's try to create a new rating.
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
stars.
I will add them for for the moment, I will just remove the description here.
And we are trying to send the stars.
Three So what will happen here?
User and movie is required so I can do movie.
We remember from the previous if I will go movies here that will open a new tab and let's send a use
movies here.
So we have ID one and ID two.
Let's create a.
Movie one.
We need to pass ID for that movie and then user.
So what is actually our user?
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
get the data for the login user when we will have authentication.
But if at the moment, if we go to the users here and I will click on the Christian, you can see here
user one change URL that means this is the ID of that user and in fact it is the first user in the database
because we've created that one so we can be sure the ID is one.
So basically what we are doing here is we are trying to create a rating.
We are trying to create a rating with a stars three stars for Movie one, which is our Titanic, and
we are using our user, which is also one.
So let's try to do this now.
And you can see here rating that's ID of the rating.
And then we have three stars for this user and for this movie.
So if I will try to create a new one and The Post is creating new records, so let's say I would like
to change it for four and I will send it.
Now, what will happen is the field user movie must be a unique set and this is what I will.
I told you about it when we had it.
This models unique together here so.
What we are trying to do here is we are trying to create a new record, new rating with the movie and
user that are the same that already exist in our database.
We have our rating for this movie and we have a rating for this user already.
So that will throw an error.
And the reason for this is that unique together, this is form you uniqueness the user and movie.
We cannot have the same one in the database.
But we could use method put.
If I will put it now.
And you can see but is not allowed here because we haven't specified what to do with the put yet.
That's unique together.
Also, it's kind of changing the way we can use our application and we will create actually our own
method later on and we can do all the validation and all our logic.
We can have it in there, but at the moment we can see this is not available.
Okay, so let's try to create a new one.
So I will do the post, but instead of the movie one that we already had our rating on, let's create
a new movie.
I mean create new ratings for a new movie, which is this movie here, Avatar.
And let's try to create a ten stars.
And then you can see ensure the value is less than or equal five.
So if I will try to do zero.
Ensure this value is greater or equal to one.
And the reason we see that.
Message is this validators we have here minimum value and the maximum value.
So you can see here when we write this, this maybe had no sense, but now when we start using our application
and we start to pass some values that won't fit our database, then we can see some very useful information
here.
And actually this will prevent us from from passing this.
And in the same way, if I will try to pass any string here, you can see a valid integer is required.
So Django is doing that, that validation for us.
We decided that this field is integer, so it will validate basically on the type.
So integer only will be accepted, not the strings like here.
And also we need to pass a correct number so we accept everything from 1 to 5.
But if we will pass something outside of that range, then it won't be accepted because we told the
validators to validate our input.
So basically that's how it works.
We have a lot of things to do here.
So what we also need to do, we need to allow users to log in, retrieve the users from the database,
and that user can be used for passing the ratings.
Also, we need to create our own method for having the ratings, and in this way we can actually disable
built in and just focus for, put and post our own.
And also we need to create a few more serializers and having some build methods to put something more
in the movies.
At the moment we don't display a serializer, we don't display any information about the ratings here,
but we could possibly do that.
So we will do that in the next videos.