Skip to main content

Module list_params

Module list_params 

Source
Expand description

Shared list-endpoint query-parameter helpers — one place that owns the reserved-key skip list, ?ordering= parsing and ?page_size= clamping, so viewset::handle_list and template_views::ListView cannot drift apart. Query-parameter parsing shared by list endpoints.

viewset::handle_list and the ListView CBV read the same parameters: ?page=N, ?ordering=col, ?search=term, and the model’s own filter keys. This module holds the parts they must agree on:

Each layer still builds its own WHERE clause, because viewset supports a richer filter syntax than the CBV.

Enums§

InListTooLong
A __in list longer than MAX_IN_VALUES, or __in lists whose sum passes in_values_budget.

Constants§

MAX_IN_VALUES
Most values one ?field__in= list may carry. Far under every dialect’s bind limit, so a long list is a 400, not a driver error (#1865).
RESERVED_LIST_KEYS
Query keys that control paging, sorting and search. A list handler must never treat one of these as a model filter, even if a column has the same name.

Functions§

clamp_page_size
Work out the page size from ?page_size=N.
in_values_budget
Most __in values one request may carry over all its lists, so a dialect with max_bind_params binds gets a 400 rather than a driver 500.
is_reserved_list_key
true when key is one of RESERVED_LIST_KEYS. Use it to skip these keys before parsing filters:
page_offset
Row offset of 1-based page. Saturates, so a huge page is an empty page rather than a wrapped negative OFFSET (#1865).
parse_ordering
Parse ?ordering=col,-col2,col3 into OrderItems. A leading - means descending.
parse_page
?page=N, 1-based. Missing, garbage, zero or negative gives page 1.
split_in_list
Split a comma-separated __in value, dropping empty entries. Stops reading past the cap, so a 2 MB body is not split in full.