rest_framework.filters

Provides generic filtering backends that can be used to filter the results returned by list views.

Module Contents

class BaseFilterBackend

Bases:object

A base class from which all filter backend classes should inherit.

filter_queryset(self, request, queryset, view)

Return a filtered queryset.

get_schema_fields(self, view)
class SearchFilter

Bases:rest_framework.filters.BaseFilterBackend

search_param
template = rest_framework/filters/search.html
lookup_prefixes
search_title
search_description
get_search_fields(self, view, request)

Search fields are obtained from the view, but the request is always passed to this method. Sub-classes can override this method to dynamically change the search fields based on request content.

get_search_terms(self, request)

Search terms are set by a ?search=… query parameter, and may be comma and/or whitespace delimited.

must_call_distinct(self, queryset, search_fields)

Return True if ‘distinct()’ should be used to query the given lookups.

filter_queryset(self, request, queryset, view)
to_html(self, request, queryset, view)
get_schema_fields(self, view)
class OrderingFilter

Bases:rest_framework.filters.BaseFilterBackend

ordering_param
ordering_fields
ordering_title
ordering_description
template = rest_framework/filters/ordering.html
get_ordering(self, request, queryset, view)

Ordering is set by a comma delimited ?ordering=… query parameter.

The ordering query parameter can be overridden by setting the ordering_param value on the OrderingFilter or by specifying an ORDERING_PARAM value in the API settings.

get_default_ordering(self, view)
get_default_valid_fields(self, queryset, view, context={})
get_valid_fields(self, queryset, view, context={})
remove_invalid_fields(self, queryset, fields, view, request)
filter_queryset(self, request, queryset, view)
get_template_context(self, request, queryset, view)
to_html(self, request, queryset, view)
get_schema_fields(self, view)
class DjangoObjectPermissionsFilter

Bases:rest_framework.filters.BaseFilterBackend

A filter backend that limits results to those where the requesting user has read object level permissions.

perm_format = %(app_label)s.view_%(model_name)s
filter_queryset(self, request, queryset, view)