WEBVTT
Kind: captions
Language: en

00:00:00.050 --> 00:00:05.640
Next we're going to add the ability to
search profiles by a specific name or

00:00:05.640 --> 00:00:11.250
email address
adding the functionality to filter items

00:00:11.250 --> 00:00:16.680
in a view set is fairly straightforward
all you need to do is open up the views

00:00:16.680 --> 00:00:22.320
dot py file and then we're going to import
the filters module from the rest

00:00:22.320 --> 00:00:28.380
framework so below this rest framework
dot authentication let's type from rest

00:00:28.380 --> 00:00:35.850
underscore framework import filters out
of the box the rest framework comes with

00:00:35.850 --> 00:00:40.460
some modules that we can use to add
filtering to a view set really easily

00:00:40.460 --> 00:00:46.620
all you do is in the user profile view
set below the permissions classes list

00:00:46.620 --> 00:00:53.750
we add a new class variable called
filter underscore back ends equals

00:00:53.750 --> 00:01:02.489
filters dot search filter remember to
add a comma after the search filter so

00:01:02.489 --> 00:01:07.909
Python knows that this is intended to be
a tuple and not a single item

00:01:07.909 --> 00:01:13.710
okay below the filter back ends we need
to add one more class variable called

00:01:13.710 --> 00:01:18.000
search fields
this tells the filter back-end which

00:01:18.000 --> 00:01:22.770
fields we're going to make searchable by
this filter so type search underscore

00:01:22.770 --> 00:01:28.049
fields equals and then a new tuple here
and we're going to make it searchable by

00:01:28.049 --> 00:01:35.200
the name field and the email field

00:01:35.200 --> 00:01:38.549
okay so what this will do is it will add a

00:01:38.549 --> 00:01:42.899
filter back end and you can add one or
more filter back ends to a particular

00:01:42.899 --> 00:01:47.579
view set we're going to add a filter
back end for the search filter which is

00:01:47.579 --> 00:01:51.090
something that comes with Django rest
framework and then we'll specify the

00:01:51.090 --> 00:01:57.299
search fields name and email this will
mean that the Django rest framework will

00:01:57.299 --> 00:02:04.380
allow us to search for items in this
view set by the name or email field okay

00:02:04.380 --> 00:02:09.989
so make sure you save the file and
that's how you add search filtering to a

00:02:09.989 --> 00:02:14.000
view set in the Django rest framework

