Django Admin support


viewflow.fsm.FlowAdminMixin adds transitions views to the standard Django Model admin interface.

After you defined a flow around django models as described in Wrapping Django Models you can add FlowAdminMixin to the ModelAdmin and define flow_state attribute

If your flow class has single constructor with only one argument - the django object been wrapped, the admin interface would automatically discover that

The flow class construction could be overridden in the get_object_flow method

from django.contrib import admin
from viewflow import fsm
from .flows import ReviewFlow
from .models import Review

class ReviewFlowAdmin(fsm.FlowAdminMixin, admin.ModelAdmin):
    readonly_fields = ('stage', )

    flow_state = ReviewFlow.stage

    def get_object_flow(self, request, obj):
        return ReviewFlow(
            obj, user=request.user,

Change object data

get_transition_fields method could be overridden to allow an admin user change specific object fields alongside with transition execution.

def get_transition_fields(self, request, obj, slug):
    if slug == 'approve':
        return ['text', 'comment']

Custom transition view

To completely override transition view, specify custom url entry in the get_urls method

def get_urls(self):
    return [path(
    )] + super().get_urls()

def reject_view(self, request, object_id):
    obj = get_object_or_404(self.model, pk=object_id)
    flow = self.get_object_flow(request, obj)

    if not flow.reject.has_perm(request.user) or not flow.reject.can_proceed():
        raise PermissionDenied

    if request.method == "POST":
        return redirect('../../')

    return render(request, ...)


FlowAdminMixin plays well with reversion.admin.VersionAdmin