Skip to main content

Creating a Workflow

A workflow class defines the full lifecycle of a model — its statuses, which transitions are allowed, and what logic runs during them. Create it in a workflow.py file inside your module.

Import

from ...packages.workflow.base.engine import WorkflowBase

:::info Relative Import Depth

Module locationDots needed
backend/patients/workflow.pyfrom ...packages (3 dots)
backend/masters/orders/workflow.pyfrom ....packages (4 dots)
:::

Minimal Example

from ...packages.workflow.base.engine import WorkflowBase
from .models import Patient

class PatientWorkflow(WorkflowBase):

status_transitions = [
{
"name": "inactivate",
"display_name": "Deactivate",
"description": "Deactivate the patient record",
"confirmation_message": "Are you sure you want to deactivate?",
"from": "active",
"to": "inactive",
},
{
"name": "activate",
"display_name": "Activate",
"description": "Activate the patient record",
"confirmation_message": "Are you sure you want to activate?",
"from": "inactive",
"to": "active",
},
]

class Meta:
model = Patient
on_create_status = "active" # status assigned when a record is created
statuses = {
"active": {"color": "#12B76A", "label": "Active"},
"inactive": {"color": "#F04438", "label": "Inactive"},
}

Attach to a CRUD View

Import and attach the workflow class to your BaseCrudView:

from ...packages.crud.base import BaseCrudView
from .tables import PatientTable
from .forms import PatientForm
from .workflow import PatientWorkflow

class PatientCrudView(BaseCrudView):
page_title = "Patients"
add_btn_title = "Add Patient"
table = PatientTable
form = PatientForm
workflow = PatientWorkflow # ← attach here

Once attached, the CRUD view automatically:

  • Sets on_create_status when a new record is created
  • Shows available transitions as action buttons in the detail view
  • Renders the current status badge via WorkflowStatus on the frontend

Full Structure Summary

PartWherePurpose
status_transitionslist on the classAll allowed moves between statuses
Meta.modelinner classThe model this workflow manages
Meta.on_create_statusinner classStatus assigned on record creation (required)
Meta.statusesinner classStatus display labels and colours
<name>_condition()methodGate — can this transition happen?
<name>_done()methodHook — runs after transition completes
tag_transitionslist on the classOptional tag enable/disable rules
Meta.tagsinner classOptional secondary flags