From the course: Building React and Django Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Filtering with Django

Filtering with Django

From the course: Building React and Django Apps

Start my 1-month free trial

Filtering with Django

- [Male Speaker] Now we want to be able to narrow down the user search for the perfect tour package. We're going to do this by using the base filter, which we import from REST framework. And we also use the search filter. We're going to filter tour packages by their price. So, we create a new package price filter backend. And we define the queryset filter. And the current filters are empty. And we are going to check the query parameters of the incoming request, "searching for price min," and the default will be "none." And if the minimum price is set, we're going to add that filter. The price has to be greater than or equal to the minimum price. We're going to do the same for the maximum price. Difference is, that the price has to be less than or equal to the maximum price. After we've set up these filters, we can return the queryset filtered by those filters. Now, in the Public Package View set, we have to set up…

Contents