Drill-Down Reports
Developer guide for the Enezaframework reporting engine. Part of the Add Report series.
Table of Contents
Overview
DrillDownReportView renders a hierarchy the user navigates level by level — for example
Region → Branch → Sales Person. Each level is described by a HierarchyLevel dataclass;
the generator produces rows for one level at a time and reports whether a row can be
drilled into.
Hierarchy Model
flowchart TD
L0["Level 0 — Region<br/>display_field: name"]
L1["Level 1 — Branch<br/>parent_field: region"]
L2["Level 2 — Sales Person<br/>parent_field: branch"]
L0 -->|drill| L1
L1 -->|drill| L2The view passes level_index and path_ids to the generator to render a given level.
Over HTTP these are ?level=<n> and repeated ?path=<id> query parameters
(enezareporting/views.py).
HierarchyLevel Fields
HierarchyLevel is a dataclass in enezareporting/report_types.py:
| Field | Default | Description |
|---|---|---|
model |
— (required) | Django model for this level. |
display_field |
— (required) | Field name shown in the UI. |
parent_field |
"" |
FK field name pointing to the parent level's model. |
value_field |
"pk" |
Numeric field used for aggregation. |
aggregation |
"sum" |
Aggregation name: sum, count, avg, min, max. |
label |
"" |
Human-readable label; defaults to the model's verbose name. |
columns |
None |
Custom column list for this level. |
Attributes
| Attribute | Required | Description |
|---|---|---|
hierarchy |
Yes | List of HierarchyLevel objects defining each level. |
max_depth |
No | Maximum drill-down depth (default: 5). Clamped to len(hierarchy). |
Example
python
from enezareporting.report_types import HierarchyLevel
from enezareporting.report_base import DrillDownReportView
from myapp.models import Region, Branch, SalesPerson
class SalesDrillDown(DrillDownReportView):
report_title = "Sales Drill-Down"
max_depth = 3
hierarchy = [
HierarchyLevel(
model=Region,
display_field="name",
label="Regions",
columns=["name", "code"],
),
HierarchyLevel(
model=Branch,
display_field="name",
parent_field="region",
label="Branches",
columns=["name", "branch_code", "manager"],
),
HierarchyLevel(
model=SalesPerson,
display_field="name",
parent_field="branch",
value_field="total_sales",
aggregation="sum",
label="Sales People",
columns=["name", "email", "total_sales"],
),
]
Validation
DrillDownReportView raises ImproperlyConfigured at class creation when hierarchy is
empty, and clamps max_depth to the hierarchy size.