Now that we've added the search filter to our API view set let's go ahead and
test this in the browser open up the git bash or the terminal window and just
check that the development server reloaded when we last saved our changes
to the views dot py file if it hasn't reloaded then just push ctrl C to close
the server and then start the development server again to make sure
the latest code is loaded into the server once that's done you can open up
the browser and if you still have the window open from the previous videos
then just take note of this area here you can see that there's no option next
to the options button but if we refresh the page you can see that the filters
option is added this is because we added the filters back end to our REST API
view set and the Django rest framework gave us this option to help test this
feature in the browser so if we click on the filters it will allow us to search
for a particular item in our view set and because we specified the email and
the name as the search field it will search for anything containing or any
name or email containing the string that we provide here so just to test the API
we're going to create one more user I'm going to call it brooke@londonappdev.com
and then we'll write the name Brooke and I'm going to put the password
password 1 2 3 and click on post to create the new user you can see that a new
user has been created so let's head back to the user profile list and you can see
that the Brooke user has been added to the list so let's go ahead and test our
filters click on the filter here and let's search for the name Brooke and you
can see that it filters a result to all of those containing the name Brooke and
we can do the same thing for my name or the name of another user so for example
mark if you search for mark you'll see the results with the word mark if you
search for test you can see all the results containing the name test ok so
let's have a little look into how this is working here so the filters
option in reality you're not going to be clicking it in the browser when you use
your API you're going to be using it from a different application so the way
it works is the filters button adds this search parameter here as a get parameter
to the request so all it does is it puts the question mark to signify the first
get parameter and it has a parameter called search that's the name of the
parameter and it has a value called test so we can manipulate this manually in
the browser URL and we can apply the search like this so if we search for the name
mark you can see that it applies the search and returns the name mark we
search for the number two you can see that it returns the same result because
it's the only one that contains the number two if we put the words or the
letters a hit enter or actually it needs to be question mark search equals a hit enter
then you can see it returns all of them because they all contained the letter A
so this is how you would apply the search parameter when you consume the
API you would add it to the URL and then the Django rest framework would filter
it accordingly okay so that's how you add search
filtering in the API now we can see that that's working let's go ahead
and commit our changes to git so open up the terminal or the git bash and open up
a window that is on our profiles API project and type git add dot to add any
new files and then type git commit - am and then we'll give it the
commit message added searching to user Profile API
Okay hit enter and then do
git push origin to push our changes to github