Now that we've created our viewset
let's go ahead and test it. Minimize atom
and load up the git bash or the terminal
that's connected to our server. Just make
sure that the server is still running
here you can see that my server is
running just fine
and then minimize this and open up
Chrome. Here we are on our hello viewsets
list. Refresh the page and we'll see all
the new options that have been
added. You can see on this page we have
the new post function. So we have an
option to create a new object
click on the HTML form tag and let's
just test that this works, so
we'll do test. Or, actually I'm going to
give it my name, Mark and click on post
and there goes it says message hello
mark. Let's test the validation by typing
a longer name then 10 characters so
Mark Winterbottom and it says
ensure this field has no more
than 10 characters. So great it seems the
validation is working. Now because we're
using a viewset, viewsets work based on
specific object IDs. So in our viewsets
page we can see the git or the list
function, so this is listing the objects
in our viewset this is creating a new
object
in our viewset. If we want to view a
specific object then we need to provide
an ID here. So let's append 1 or you
can append anything you want but let's
try just 1 as the primary key ID and
hit enter. Now you can see it's returned
what's called a detail view. So a detail
view is a specific object that's
retrieved from the database. So typically
what you'll have is on the root view
that's just hello viewset you would
have a list of the objects in the
database and usually this would be like
a preview so maybe like the ID and the
first name. And then if you wanted to see
more
what details about a specific object you
would provide the idea of an object in
the URL and it would retrieve the full
object from the database. This is called the
detail view. From this view in Django
rest framework we can also update the
object. So, we provided a name field in
our serializer
so let's just say we added a name Mark
and we put 'put' it would call the HTTP
put function with the details that we
provided. Also, why we're on the specific object
we can do the patch. So the patch as I
mentioned before is a partial update of
the object. So just to test it let's
provide a blank JSON object and hit
patch. You can see it returns HTTP method
patch. Finally let's test the delete
function by clicking delete here, it's
asking if we want to delete this
instance, click on delete and it returns
HTTP method delete. So we can see that our
viewset is working as expected
let's minimize the Chrome window and
open up the git bash that is the one on
our local machine in our project and
commit our changes to git. Type: git add
to add the new files that we created and
then type git commit -am and we'll
describe the changes we made so we "Added
create, retrieve, update, partial update
and destroy methods to our viewset. Hit
enter to finalize the commit. Okay so
that's how we test our viewset. Thank
you for watching, I hope you found this
video useful and I'll see you in the
next lesson.