Finally let's test our view set in the browser open up your browser and head
over to the view set or hello view set URL that we had open earlier and refresh
the page to reveal the new post function has been added to our view set so just
like with our API view the Django rest framework browsable API knows that our
view set is going to accept a post with a name because we assigned the
serializer class to the top of our view set and it looks at the serializer and
it determines which fields we're going to accept in the request that we
make to the api and it provides them here for us in the handy browsable api
view so if we add our name here to the input click post you can see that it
generates the message hello and the name that was provided if we put the name
with too many characters more than 10 and do post then we see that we get the
validation errors returned to us when we make the request
okay unlike the API view we don't actually see the put patch and delete
methods here on the hello view set API that's because view sets expect that you
will use this endpoint to retrieve a list of objects in the database and you
will specify a primary key ID in the URL when making changes to a specific object
so if we want to see these additional functions that we added we need to add
something to the end of the URL now in in this case because we aren't actually
retrieving any real objects it doesn't matter what you type but if you just put
a number here that would represent a primary key of an object that you wanted to
change and hit enter then it will change the page to the get request which is the
retrieve of that object so when you specify a primary key to a view set URL
it calls the retrieve function and as you can see in our retrieve function we
return this response HTTP method get which you can see here
in the browser then you can perform various updates and delete functions on
the different objects so if you hit delete then it will call the destroy
function that we defined which will return HTTP method delete you can also
perform updates on the object so by default you will perform a put update so
if we do a test input here and click put you can see that it returns the HTTP
method put and that will be from our update function
Finally if you want to
do a partial update then you need to click on the raw data tab here and then
you can see you get the put and patch options if you click on patch it returns
the HTTP method patch and that's because that's what we returned from our partial
update function that we defined
Okay so it looks like our view set is working as
expected let's go ahead and commit our changes and push them to github open up
the terminal and open a fresh window that is on our project and type git add
dot to add any new files and git commit -
am and we'll write the message added view set to profiles API
hit enter and then do git push origin to push all of the changes up to github