Sha256: e6a39cab715f3d0a47aa0b1f56333dd9ba36b503dbc7500484f4ccdd8c722258
Contents?: true
Size: 1.99 KB
Versions: 3
Compression:
Stored size: 1.99 KB
Contents
--- layout: default title: Filtering / Ordering position: 4 slug: filtering-and-ordering --- # Filtering and Ordering While you can control the recordset that the API exposes, sometimes you want the user to control the records they want to see, or the order of those records. Both filtering and ordering are accomplished through a generic mechanism called "filters". To control the filter backends that a controller uses, you can either adjust the `filter_backends` controller attribute or you can override the `get_filter_backends()` method. ## ModelQueryFilter This filter provides basic user-controllable filtering of the recordset using query params. For example, a request to `/api/movies?cool=true` would return movies where `cool` is `true`. If you include `ModelControllerMixin` into your controller, `ModelQueryFilter` is included in the filter backends by default. ## ModelOrderingFilter This filter provides basic user-controllable ordering of the recordset using query params. For example, a request to `/api/movies?ordering=name` could order the movies by `name` rather than `id`. `ordering=-name` would invert the ordering. You can also order with multiple parameters with a comma separated list, like: `ordering=director,-name`. If you include `ModelControllerMixin` into your controller, `ModelOrderingFilter` is included in the filter backends by default. You can use `ordering_fields` to controller which fields are allowed to be ordered by. To adjust the parameter that the user passes, adjust `ordering_query_param`; the default is `"ordering"`. ## ModelSearchFilter This filter provides basic user-controllable searching of the recordset using the `search` query parameter (adjustable with the `search_query_param`). For example, a request to `/api/movies?search=Star` could return movies where `name` contains the string `Star`. The search is performed against the `search_fields` attribute, but if that is not set, then the search is performed against a configurable default set of fields (`search_columns`).
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rest_framework-0.9.5 | docs/_guide/4_filtering_and_ordering.md |
rest_framework-0.9.4 | docs/_guide/4_filtering_and_ordering.md |
rest_framework-0.9.3 | docs/_guide/4_filtering_and_ordering.md |