From the course: Building Angular 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 Angular and Django Apps

Start my 1-month free trial

Filtering with Django

- [Instructor] We already implemented a filter on the Django side for checking permissions of whether or not a user can access or write to a particular package. Now, we want an additional filter. Going to add that after the previous filter. Going to call it TourLengthFilterBackend. It's also a subclass of BaseFilterBackend. And, again, we override the filter_queryset method. And we are going to extract the tour length value from the query params. And if it is set, we're going to return the queryset.filtered by the tour length. Otherwise, we just return the query set as it was. And then we add the FilterBackend here to the PackageViewSet FilterBackends list. And now, we can run our dev server. We can test this out with a curl command. First, we need to log in with our prefilled-in log-in information. Going to post to the oauth token endpoint. So we now have an access token that we can use to make further requests.…

Contents