State Visualization

django_fsm.chart() generates Graphviz DOT source for a State descriptor. Generating this text does not require Graphviz binaries.

from django_fsm import chart
from .flow import ReportFlow

dot_graph = chart(ReportFlow.state_field)
print(dot_graph)

The example uses the flow from Separate Flow Classes. To include transitions with no target state (guards), pass exclude_guards=False:

dot_graph = chart(ReportFlow.state_field, exclude_guards=False)

Rendering

Save the output as report.dot and render it with the Graphviz dot command (install Graphviz separately):

$ dot -Tpng report.dot -o report.png

To return DOT source from a Django view:

from django.http import HttpResponse
from django_fsm import chart
from .flow import ReportFlow

def flow_chart_view(request):
    return HttpResponse(
        chart(ReportFlow.state_field), content_type='text/plain'
    )

Model Field Charts

For FSMField, FSMIntegerField, and FSMKeyField transitions, install pip install 'django-fsm[graphviz]' and add django_fsm to INSTALLED_APPS to enable the management command:

$ python manage.py graph_transitions myapp.Report.state > report.dot

Replace myapp.Report.state with your application’s model and field name. Rendering an image also requires the Graphviz system package.

Integrations

The Django Admin Support and Frontend Viewset integrations display state charts. The Expose REST Interface integration exposes the DOT source at its chart/ endpoint.