Skip to main content

pypaginate.adapters.django.backend

Django pagination backends: offset slicing + keyset cursor.

Offset pagination counts via QuerySet.count() then slices (qs[offset:offset + limit]), which Django renders to LIMIT/OFFSET. Keyset pagination reuses the cross-language cursor codec and the core's portable keyset predicate (:func:pypaginate._core.keyset_terms), rendering the lexicographic WHERE to Django Q objects so cursors stay byte-compatible with the SQLAlchemy and TS adapters. The QuerySet must carry an explicit order_by over simple field names.

paginate_offset

def paginate_offset(queryset: QuerySet[T],
params: OffsetParams) -> OffsetPage[T]

Offset-paginate a QuerySet via count() + a LIMIT/OFFSET slice.

paginate_keyset

def paginate_keyset(queryset: QuerySet[T],
params: CursorParams) -> CursorPage[T]

Keyset-paginate an ordered QuerySet into a :class:CursorPage.