WEBVTT
Kind: captions
Language: en

00:00:00.030 --> 00:00:06.569
Now that we've added the search filter
to our API view set let's go ahead and

00:00:06.569 --> 00:00:13.410
test this in the browser open up the git
bash or the terminal window and just

00:00:13.410 --> 00:00:17.789
check that the development server
reloaded when we last saved our changes

00:00:17.789 --> 00:00:23.100
to the views dot py file if it hasn't
reloaded then just push ctrl C to close

00:00:23.100 --> 00:00:26.550
the server and then start the
development server again to make sure

00:00:26.550 --> 00:00:32.340
the latest code is loaded into the
server once that's done you can open up

00:00:32.340 --> 00:00:36.960
the browser and if you still have the
window open from the previous videos

00:00:36.960 --> 00:00:42.059
then just take note of this area here
you can see that there's no option next

00:00:42.059 --> 00:00:47.129
to the options button but if we refresh
the page you can see that the filters

00:00:47.129 --> 00:00:52.379
option is added this is because we added
the filters back end to our REST API

00:00:52.379 --> 00:00:57.180
view set and the Django rest framework
gave us this option to help test this

00:00:57.180 --> 00:01:03.180
feature in the browser so if we click on
the filters it will allow us to search

00:01:03.180 --> 00:01:08.760
for a particular item in our view set
and because we specified the email and

00:01:08.760 --> 00:01:13.049
the name as the search field it will
search for anything containing or any

00:01:13.049 --> 00:01:17.670
name or email containing the string that
we provide here so just to test the API

00:01:17.670 --> 00:01:23.840
we're going to create one more user I'm
going to call it brooke@londonappdev.com

00:01:23.840 --> 00:01:26.640
and then we'll write the name Brooke and I'm going to put the password

00:01:26.640 --> 00:01:32.820
password 1 2 3 and click on post to
create the new user you can see that a new

00:01:32.820 --> 00:01:38.520
user has been created so let's head back
to the user profile list and you can see

00:01:38.520 --> 00:01:44.700
that the Brooke user has been added to
the list so let's go ahead and test our

00:01:44.700 --> 00:01:49.290
filters click on the filter here and
let's search for the name Brooke and you

00:01:49.290 --> 00:01:53.930
can see that it filters a result to all
of those containing the name Brooke and

00:01:53.930 --> 00:01:59.790
we can do the same thing for my name or
the name of another user so for example

00:01:59.790 --> 00:02:05.250
mark if you search for mark you'll see
the results with the word mark if you

00:02:05.250 --> 00:02:11.580
search for test you can see all the
results containing the name test ok so

00:02:11.580 --> 00:02:15.900
let's have a little look into
how this is working here so the filters

00:02:15.900 --> 00:02:20.550
option in reality you're not going to be
clicking it in the browser when you use

00:02:20.550 --> 00:02:25.650
your API you're going to be using it
from a different application so the way

00:02:25.650 --> 00:02:32.040
it works is the filters button adds this
search parameter here as a get parameter

00:02:32.040 --> 00:02:39.150
to the request so all it does is it puts
the question mark to signify the first

00:02:39.150 --> 00:02:44.610
get parameter and it has a parameter
called search that's the name of the

00:02:44.610 --> 00:02:50.280
parameter and it has a value called test
so we can manipulate this manually in

00:02:50.280 --> 00:02:56.040
the browser URL and we can apply the
search like this so if we search for the name

00:02:56.040 --> 00:03:01.410
mark you can see that it applies the
search and returns the name mark we

00:03:01.410 --> 00:03:05.250
search for the number two you can see
that it returns the same result because

00:03:05.250 --> 00:03:11.310
it's the only one that contains the
number two if we put the words or the

00:03:11.310 --> 00:03:18.209
letters a hit enter or actually it needs to
be question mark search equals a hit enter

00:03:18.209 --> 00:03:21.510
then you can see it returns all of them
because they all contained the letter A

00:03:21.510 --> 00:03:27.030
so this is how you would apply the
search parameter when you consume the

00:03:27.030 --> 00:03:31.980
API you would add it to the URL and then
the Django rest framework would filter

00:03:31.980 --> 00:03:36.660
it accordingly
okay so that's how you add search

00:03:36.660 --> 00:03:40.080
filtering in the API now we can
see that that's working let's go ahead

00:03:40.080 --> 00:03:46.140
and commit our changes to git so open up
the terminal or the git bash and open up

00:03:46.140 --> 00:03:53.670
a window that is on our profiles API
project and type git add dot to add any

00:03:53.670 --> 00:03:59.730
new files and then type git commit -
am and then we'll give it the

00:03:59.730 --> 00:04:08.300
commit message added searching to user Profile API

00:04:08.300 --> 00:04:10.170
Okay hit enter and then do

00:04:10.170 --> 00:04:15.500
git push origin to push our changes
to github

