Configuration¶
QueryStringManager reads settings from Django NINJA_JSONAPI.
Settings¶
NINJA_JSONAPI = {
"DEFAULT_PAGE_SIZE": 20,
"MAX_PAGE_SIZE": 100,
"MAX_INCLUDE_DEPTH": 3,
"ALLOW_DISABLE_PAGINATION": False,
"INCLUDE_JSONAPI_OBJECT": False,
"JSONAPI_VERSION": "1.0",
}
Keys¶
DEFAULT_PAGE_SIZE: default number of items per page when the client doesn't sendpage[size]. Used by bothApplicationBuilderviews and the standalonejsonapi_paginate()helper.MAX_PAGE_SIZE: hard upper limit forpage[size]. Client-requested sizes above this value are clamped silently.MAX_INCLUDE_DEPTH: maximum include chain depth (for examplea.b.c).ALLOW_DISABLE_PAGINATION: allows/disallowspage[size]=0.- When
True,page[size]=0disables pagination. - When
False,page[size]=0falls back to the default page size.
- When
INCLUDE_JSONAPI_OBJECT: whenTrue, adds top-leveljsonapiobject to responses. Applies to bothApplicationBuilderand standalone@jsonapi_resourceendpoints.JSONAPI_VERSION: version string used whenINCLUDE_JSONAPI_OBJECT=True.INFLECTION: attribute-key transformation applied to JSON:API documents.None(default) — keys match Python field names."dasherize"—first_name→first-name."camelize"—first_name→firstName.- See Inflection for details.
Practical guidance¶
- Keep
MAX_INCLUDE_DEPTHconservative to avoid expensive graph traversal. - Set
MAX_PAGE_SIZEbased on endpoint cost and typical client use. - Use per-resource operation limits when read-heavy resources need stricter controls.
Query parameters supported¶
filterfilter[field]=valuesortincludefields[resource_type]page[number],page[size],page[offset],page[limit]page[cursor](cursor pagination)
Query parameter validation¶
- Unknown query parameters are rejected with
400 Bad Request. - Repeated parameters are rejected for non-
filterkeys (for example repeatingsortorpage[size]). - Repeating
filter[...]keys is allowed.
Include-query optimization¶
The Django ORM data layer now optimizes include paths automatically:
- to-one include chains use
select_related - to-many include chains use
prefetch_related
You can also provide explicit include optimization maps on your view:
from django_ninja_jsonapi import ViewBaseGeneric
class CustomerView(ViewBaseGeneric):
select_for_includes = {
"__all__": ["company"],
"owner": ["owner__profile"],
}
prefetch_for_includes = {
"owner": ["owner__groups"],
}
django_filterset_class = CustomerFilterSet
Resource meta fields¶
To move selected schema fields into resource meta, define meta_fields: