Workflow Query JSON Format
Developer guide for the Enezaframework workflow engine. Part of the Workflow series.
Table of Contents
- Overview
- Rules-Style Format
- Groups-Style Format
- Annotation Entry Schema
- Rule Entry Schema
- Related Guides
Overview
SavedQuery.filters_json stores the query builder output. The enhancements add an optional top-level annotations array; everything else is unchanged. SavedQuery.get_queryset() picks the parser based on whether groups is present (enezaworkflowengine/models/querybuilder.py:44-52).
flowchart TD
FJ["filters_json"] --> G{"has 'groups'?"}
G -->|Yes| P1["parse_new_query_format_to_q()"]
G -->|No| P2["parse_rules_to_q()"]
FJ --> A{"has 'annotations'?"}
A -->|Yes| ANN["parse_annotations() -> annotate()"]
A -->|No| SKIP["No aggregation"]Rules-Style Format
json
{
"condition": "AND",
"annotations": [
{
"function": "sum | count | avg | min | max",
"field": "field_name_on_related_model",
"related_model": "relation_accessor_name",
"alias": "output_name_for_filter_rules"
}
],
"rules": [
{
"id": "field_or_alias",
"field": "field_or_alias",
"type": "string | integer | double | boolean | date | datetime",
"operator": "equal | not_equal | contains | greater | ...",
"value": "value_to_compare"
}
]
}
This is the format used when groups is absent.
Groups-Style Format
json
{
"condition": "AND",
"primary_model": "frameworktestdocument",
"related_models": ["lines"],
"annotations": [
{
"function": "sum",
"field": "amount",
"related_model": "lines",
"alias": "total_amount"
}
],
"groups": [
{
"condition": "AND",
"rules": [
{
"id": "total_amount",
"field": "total_amount",
"type": "double",
"operator": "greater",
"value": "1000"
}
]
}
]
}
primary_model and related_models describe the shape; the rules live in groups. Annotation handling is identical in both formats.
Annotation Entry Schema
| Key | Type | Required | Description |
|---|---|---|---|
function |
string |
Yes | sum, count, avg, min, or max |
field |
string |
Yes* | Field on the related model to aggregate |
related_model |
string |
Yes | FK/M2M field name, or reverse relation accessor, on the primary model |
alias |
string |
Yes | Output name referenced by filter rules |
* field is optional for count; when omitted, the lookup is the relation itself (Count('lines')). See Workflow Aggregate Annotations.
Rule Entry Schema
| Key | Type | Required | Description |
|---|---|---|---|
id |
string |
Yes | Rule identifier; for an aggregate rule it must equal the annotation alias. |
field |
string |
Yes | A model field name, a related lookup, or an annotation alias. |
type |
string |
Yes | Value type used for coercion: string, integer, double, boolean, date, datetime. |
operator |
string |
Yes | Comparison operator, for example equal, not_equal, contains, greater, less. |
value |
string |
Yes | Value to compare against. |