Adding filtering, searching, and ordering
Now, we will add the necessary code to configure the fields that we want to be included in the filtering, searching, and ordering features for each of the class-based views that retrieve the contents of each resource collection. Hence, we will make changes to all the classes with the List
suffix in the views.py
file: DroneCategoryList
, DroneList
, PilotList
, and CompetitionList
.
We will declare the following three class attributes in each of those classes:
filter_fields
: This attribute specifies a tuple of strings whose values indicate the field names that we want to be able to filter against. Under the hood, the Django REST framework will automatically create arest_framework.filters.FilterSet
class and associate it to the class-based view in which we are declaring the attribute. We will be able to filter against the field names included in the tuple of strings.search_fields
: This attribute specifies a tuple of strings whose values indicate the text...