Aggregate objects of resource.
GET/:api_prefix/:service_name/admin/:resource_name/aggregate
Premium — provided by the paid habarico-enterprise package; a free-only install does not expose this endpoint.
Computes an aggregation over the resource objects matching the optional filter
query parameters. Reuses the same filter_queryset / ComplexFilterBackend
as the resource list endpoint, so widget filters apply identically.
Optional endpoint. Available only on resources where the admin opts in via
ModelAdmin. Resources without the opt-in return HTTP 404 for this path. The
availability is signalled in the resource schema via aggregate_enabled: true
(see GlobalResourceSchema).
Aggregation target
count–fieldis ignored.min/max/sum/avg–fieldis required and must include the chosen function in itsaggregationswhitelist (seeFieldSchema.aggregations).
Grouping via group_by
group_by is a repeat-style query parameter
(?group_by=field1&group_by=field2:trunc:month). Each item has the form
<field>[:<bucket_fn>[:<arg>]]:
<field>– plain field name. Each field must includeexactin itsFieldSchema.group_bywhitelist.<field>:trunc:<gran>– date / datetime truncation.granis one ofsecond,minute,hour,day,week,month,quarter,year. Field must includetrunc:<gran>in itsgroup_bywhitelist. Bucket labels are ISO 8601 timestamps in the active Django timezone (TIME_ZONEsetting, optionally overridden per-request via Django's standard timezone middleware /timezone.activate()). Implemented on the backend with Django ORMTruncSecond/TruncMinute/TruncHour/TruncDay/TruncWeek/TruncMonth/TruncQuarter/TruncYear.<field>:width:<n>– numeric fixed-width bucketing into[0, n),[n, 2n), … Bucket labels are the lower bounds. Field must includewidthin itsgroup_bywhitelist.
With no group_by the response contains a single bucket with the scalar value.
Limits and safety
- Whitelist via
aggregations/group_byonFieldSchemaprevents SQL injection and schema leaks. Fields without an entry are rejected with HTTP 422. - Hard limit on the number of returned buckets (default 50) – exceeding the limit yields HTTP 422.
- Row-level permissions are inherited from
get_queryset, so aggregates reflect only rows the current user is allowed to see.
Request
Responses
- 200
- 404
- 422
Premium — returned only by the paid habarico-enterprise package.
Aggregate result (HTTP 200). One bucket per combination of group_by keys, or a
single bucket when no group_by is requested.