Skip to main content

Transitions & Workflows

Ralph’s transition system allows you to define workflows that change the state of objects (like assets, licenses, or support contracts) from one status to another. This enables structured lifecycle management with custom actions, validations, and permissions.

Overview

Transitions provide:
  • State management: Control how objects move between states
  • Custom actions: Execute code when transitions occur
  • Validation: Ensure preconditions are met before transitions
  • Permissions: Control who can execute transitions
  • History tracking: Audit trail of all transitions
  • Async execution: Run long-running transitions in the background
  • Attachments: Attach files generated during transitions

Basic Setup

Step 1: Define Status Field

Create a model with a TransitionField:
Source: src/ralph/lib/transitions/models.py:465-487, docs/development/transitions.md:17-33

Step 2: Define Actions

Use the @transition_action decorator to define actions:
Source: src/ralph/lib/transitions/decorators.py:7-41, docs/development/transitions.md:24-33

Step 3: Configure Transitions in Admin

After defining actions, they appear in the admin. Navigate to Transitions → Transition Models and configure:
  1. Select your model and field (e.g., Order → status)
  2. Create transitions:
    • Name: “Process Order”
    • Source: [New]
    • Target: Processing
    • Actions: [pack]
Source: src/ralph/lib/transitions/models.py:511-544, docs/development/transitions.md:35-37

Step 4: Enable in Admin

Mix TransitionAdminMixin into your admin class:
Source: src/ralph/lib/transitions/admin.py:64-140

Action Parameters

Form Fields

Add input fields to collect data during transitions:
Source: docs/development/transitions.md:42-64

Conditional Fields

Show fields only when conditions are met:
Source: docs/development/transitions.md:45-62

Excluding from History

Prevent sensitive fields from being saved to transition history:
Source: src/ralph/lib/transitions/models.py:90-100

Advanced Features

Preconditions

Validate before executing transitions:
If precondition returns errors, the transition is blocked and error messages are shown to the user. Source: src/ralph/lib/transitions/decorators.py:16, src/ralph/lib/transitions/models.py:152-195

Action Dependencies

Run actions in specific order:
Actions are executed in topological order based on dependencies. Source: src/ralph/lib/transitions/decorators.py:14, src/ralph/lib/transitions/models.py:237-254

Transition History

Store additional data in history:
History data is saved and displayed in the transition history tab. Source: docs/development/transitions.md:74-85

Sharing Data Between Actions

Pass data between consecutive actions:
Source: docs/development/transitions.md:87-90

Return Attachments

Generate and return files from transitions:
Attachments are automatically linked to the transition history and available for download. Source: docs/development/transitions.md:72, src/ralph/lib/transitions/models.py:423-428

Asynchronous Transitions

Run long-running transitions in the background:
Async transitions:
  • Run in background workers
  • Show progress in “Current Transitions” tab
  • Can be monitored and cancelled
  • Only one async transition per object at a time
Source: src/ralph/lib/transitions/decorators.py:22, src/ralph/lib/transitions/models.py:256-305

Rescheduling Async Actions

Reschedule actions to run later:
Rescheduled actions preserve history_kwargs and shared_params. Source: docs/development/transitions.md:92-96

Disable Auto-Save

Prevent automatic saving of instances:
Useful for validation-only transitions or when you need custom save logic. Source: src/ralph/lib/transitions/decorators.py:20

Custom Templates

Use custom templates for transition forms:
Then in the admin, select the template when configuring the transition. Source: docs/development/transitions.md:4-12

Permissions

Each transition automatically gets a permission:
Assign permissions to users/groups in Django admin to control who can execute transitions. Source: src/ralph/lib/transitions/models.py:545-551, src/ralph/lib/transitions/models.py:776-786

Programmatic Execution

Run transitions from Python code:
Source: src/ralph/lib/transitions/models.py:256-305

Available Transitions

Get available transitions for an object:
This method is auto-generated for each TransitionField on the model. Source: src/ralph/lib/transitions/models.py:442-462, src/ralph/lib/transitions/models.py:473-486

Complete Example

Here’s a full example of an order management system:
Now configure transitions in the admin:
  1. Process Order: NEW → PROCESSING (action: process_order)
  2. Pack Order: PROCESSING → PACKED (action: pack_order)
  3. Ship Order: PACKED → SHIPPED (action: ship_order)
  4. Mark Delivered: SHIPPED → DELIVERED (no actions)
  5. Cancel Order: [NEW, PROCESSING] → CANCELLED (action: cancel_order)

Next Steps