django-xworkflows is a django application adding xworkflows functionnalities to django models.
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_xworkflows import models as xwf_models
class MyModel(xwf_models.WorkflowEnabled):
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.
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: