django-xworkflows documentation

django-xworkflows is a django application adding xworkflows functionnalities to django models.

Getting started

First, install the required packages:

pip install django-xworkflows

In your settings.py, add django_xworkflows to your INSTALLED_APPS:

INSTALLED_APPS = (
    '...',
    'django_xworkflows',
)

Define a workflow:

from django_xworkflows import models as xwf_models

class MyWorkflow(xwf_models.Workflow):
    log_model = ''  # Disable logging to database

    states = (
        ('new', _(u"New")),
        ('old', _(u"Old")),
    )
    transitions = (
        ('get_old', 'new', 'old'),
    )
    initial_state = 'new'

And add it to a model:

from django import models
from django_xworkflows import models as xwf_models

class MyModel(xwf_models.WorkflowEnabled, models.Model):

    state = xwf_models.StateField(MyWorkflow)

The state field of MyModel is now defined as a django.db.models.CharField, whose choices and default are configured according to the related django_xworkflows.models.Workflow.

Integration with django

After each successful transition, a save() is performed on the object. This behaviour is controlled by passing the extra argument save=False when calling the transition method.

If the Workflow has a definition for the log_model attribute (as a <app>.<Model> string), an instance of that model will be created for each successful transition.

If the django_xworkflows.xworkflow_log application is installed, log_model defaults to TransitionLog. Otherwise, it defaults to '' (db logging disabled).

This behaviour can be altered by:

  • Setting the log_model attribute to ''
  • Calling the transition method with log=False (no logging to database)
  • Overriding the db_log() method of the Workflow.
  • Overriding the log_transition() method of the Workflow; this controls both log and save behaviours.

Indices and tables