Next we're going to add the ability to search profiles by a specific name or
email address adding the functionality to filter items
in a view set is fairly straightforward all you need to do is open up the views
dot py file and then we're going to import the filters module from the rest
framework so below this rest framework dot authentication let's type from rest
underscore framework import filters out of the box the rest framework comes with
some modules that we can use to add filtering to a view set really easily
all you do is in the user profile view set below the permissions classes list
we add a new class variable called filter underscore back ends equals
filters dot search filter remember to add a comma after the search filter so
Python knows that this is intended to be a tuple and not a single item
okay below the filter back ends we need to add one more class variable called
search fields this tells the filter back-end which
fields we're going to make searchable by this filter so type search underscore
fields equals and then a new tuple here and we're going to make it searchable by
the name field and the email field
okay so what this will do is it will add a
filter back end and you can add one or more filter back ends to a particular
view set we're going to add a filter back end for the search filter which is
something that comes with Django rest framework and then we'll specify the
search fields name and email this will mean that the Django rest framework will
allow us to search for items in this view set by the name or email field okay
so make sure you save the file and that's how you add search filtering to a
view set in the Django rest framework