rest_framework_json_api.filters module¶
-
class
rest_framework_json_api.filters.
OrderingFilter
¶ Bases:
rest_framework.filters.OrderingFilter
A backend filter that implements http://jsonapi.org/format/#fetching-sorting 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
withordering_param
= “sort”Also applies DJA format_value() to convert (e.g. camelcase) to underscore. (See JSON_API_FORMAT_FIELD_NAMES in docs/usage.md)
-
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).- Raises
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 http://jsonapi.org/format/#query-parameters.-
query_regex
= re.compile('^(sort|include)$|^(filter|fields|page)(\\[[\\w\\.\\-]+\\])?$')¶ compiled regex that matches the allowed http://jsonapi.org/format/#query-parameters: sort and include stand alone; filter, fields, and page have []’s
-
validate_query_params
(request)¶ Validate that query params are in the list of valid query keywords in
query_regex
- Raises
ValidationError – if not.
-
filter_queryset
(request, queryset, view)¶ Overrides
BaseFilterBackend.filter_queryset()
by first validating the query params withvalidate_query_params()
-