rest_framework_json_api.filters module

class rest_framework_json_api.filters.OrderingFilter

Bases: rest_framework.filters.OrderingFilter

A backend filter that implements and raises a 400 error if any sort field is invalid.

If you prefer not to report 400 errors for invalid sort fields, just use rest_framework.filters.OrderingFilter with ordering_param = “sort”

Also applies DJA format_value() to convert (e.g. camelcase) to underscore. (See JSON_API_FORMAT_FIELD_NAMES in docs/

ordering_param = 'sort'

override rest_framework.filters.OrderingFilter.ordering_param with JSON:API-compliant query parameter name.

remove_invalid_fields(queryset, fields, view, request)

Extend rest_framework.filters.OrderingFilter.remove_invalid_fields() to validate that all provided sort fields exist (as contrasted with the super’s behavior which is to silently remove invalid fields).


ValidationError – if a sort field is invalid.

class rest_framework_json_api.filters.QueryParameterValidationFilter

Bases: rest_framework.filters.BaseFilterBackend

A backend filter that performs strict validation of query parameters for JSON:API spec conformance and raises a 400 error if non-conforming usage is found.

If you want to add some additional non-standard query parameters, override query_regex adding the new parameters. Make sure to comply with the rules at

query_regex = re.compile('^(sort|include)$|^(?P<type>filter|fields|page)(\\[[\\w\\.\\-]+\\])?$')

compiled regex that matches the allowed sort and include stand alone; filter, fields, and page have []’s


Validate that query params are in the list of valid query keywords in query_regex


ValidationError – if not.

filter_queryset(request, queryset, view)

Overrides BaseFilterBackend.filter_queryset() by first validating the query params with validate_query_params()