django-workflow /

Filename Size Date modified Message
2.1 KB
11.9 KB
808 B
808 B
4.8 KB
1.1 KB
1.7 KB

A simple workflow mechanism for Django models; supports transition, pluggable
access control, hooks, and scripts for an admin form.

Fast and stable, used in production on some sites.

Not feature-rich, though - see TODO list.


Add 'workflow' to INSTALLED_APPS and TEMPLATE_DIRS, and ('^workflow/', include('workflow.urls')),
to urls.

Your model must inherit from WorkflowMixin 
and refer to the appropriate Workflow subclass:

class MyModel(models.Model, Workflow.WorkflowMixin):
    workflow_class = MyWorkflow
    ...other fields...

Workflow definition:

The workflow class inherits from Workflow.Workflow and defines the folowing:

 - state_list - a list of strings naming possible workflow states of the object

 - transition_list - a list of 3-4 element tuples:

(transition_name, start_state, end_state, [condition])

whereby the callable is something like:

def condition(object, user):
  return whether the user is allowed to execute the transition on the object

The workflow may also define hook methods to be executed before or after
a transition (the object is saved in the middle of transition!).


class MyWorkflow(Workflow.Workflow):
  state_list = ('draft', 'accepted')
  transition_list = (
    ('accept', 'draft', 'accepted'),
    ('withdraw', 'accepted', 'draft', is_admin),

  def after_withdraw(self):
    """mail the author"""


ob.workflow_state - current state

ob.workflow.get_transition_list(user=None) - returns a list of transitions available
from current state; if user is given checks his permissions

ob.workflow.make_transition(transition_name, user=None, message='') - execute transition.
user is checked for permissions; user and message are recorded in history.

ob.workflow_history - a pickled list of transitions executed so far

cls.bystate - search by workflow state (doesn't work through standard manager because it is not
a field anymore)


Some nicer way to search by workflow state.

Would be nice to have state entry and state exit hooks, too.

Should an action be available from many states?

Better integration with admin forms.