Reporting Quick Start

Developer guide for the Enezaframework reporting engine. Part of the Add Report series.

Table of Contents

  1. Overview
  2. Step 1 — Define the Report Class
  3. Step 2 — Register a URL
  4. What Happens on the First Request
  5. Default Parameters
  6. Related Guides

Overview

A working report needs two things: a class that subclasses one unified *ReportView base, and a URL entry. Nothing else is required — the framework supplies the filter form, the data generation, and the template.

You will build: a minimal tabular report that groups sales lines by item and shows a total column.


Step 1 — Define the Report Class

Put report classes in your app's views/reports.py (or any module that views/__init__.py imports).

python
# myapp/views/reports.py
from enezareporting.report_base import TabularReportView
from enezareporting.parameters import ParameterSet, DateRangeParam
from myapp.models import SalesLine


class SalesReport(TabularReportView):
    report_title = "Sales Report"
    report_model = SalesLine
    date_field = "date_placed"
    group_by = "item_code"
    columns = ["item_description", "__total__"]
    parameter_spec = ParameterSet(
        DateRangeParam(name="date_range", start_field="date_placed"),
    )

What each attribute does:

Attribute Purpose
report_model The Django model the report reads.
date_field The date field used for date-range filtering.
group_by The field rows are grouped by.
columns Fields, computation field names, or callables to display.
parameter_spec The filter inputs shown to the user.

Step 2 — Register a URL

python
# myapp/urls.py
from django.urls import path
from myapp.views.reports import SalesReport

app_name = "myapp"

urlpatterns = [
    path("sales-report/", SalesReport.as_view(), name="sales_report"),
]

Then navigate to /myapp/sales-report/. The filter form renders first; submitting it produces the table.


What Happens on the First Request

sequenceDiagram
    actor U as User
    participant V as Unified View
    participant P as ParameterSet form
    participant G as TabularReportGenerator
    participant T as report.html

    U->>V: GET sales-report
    V->>V: read TabularReport metadata from the class
    V->>P: build form from parameter_spec
    P-->>U: date-range form
    U->>V: submit date_range
    V->>P: cleaned_data -> Q(date_placed__gte/lte)
    V->>G: TabularReportGenerator(report_model, columns, group_by, dates)
    G-->>V: {data, columns, metadata, chart_settings}
    V->>T: render
    T-->>U: sales table

Default Parameters

Report types ship with a default parameter_spec, and the unified bases inherit it:

  • TabularReportView inherits ParameterSet(DateRangeParam(name="date_range")) with no start_field set from TabularReport (enezareporting/report_types.py:255-257). Add FKFilterParam (and a configured DateRangeParam) explicitly — the quick start above declares its own parameter_spec for exactly this reason.
  • DocumentReportView inherits ParameterSet(DocumentParam(name="document_id")) (report_types.py:221-223).
  • DrillDownReportView inherits an empty ParameterSet() (report_types.py:363).

See Report Parameters for every parameter type.