我最近遇到了 Django 的 Viewflow 库,它似乎是一个非常强大的工具,可用于创建复杂的工作流。
我的应用程序是一个简单的票务系统,工作流是通过创建票证开始的,然后用户应该能够通过 CRUD 页面创建零个或多个与票证相关联的工作日志,类似于标准的 Django 管理员 change_list/detail .
列表视图的模板应该是什么样的?我想将 UI 集成到图书馆的前端。
该流程清楚地利用了以下视图:
1) 为工单创建视图
2a) 工作日志的 ListView,模板具有控件“返回”、“添加”(转到步骤 2b)、“完成”(转到步骤 3)。
2b) 为工作日志创建视图
3) 结束
代码:
模型.py:
class TicketProcess(Process):
title = models.CharField(max_length=100)
category = models.CharField(max_length=150)
description = models.TextField(max_length=150)
planned = models.BooleanField()
worklogs = models.ForeignKey('WorkLog', null=True)
class WorkLog(models.Model):
ref = models.CharField(max_length=32)
description = models.TextField(max_length=150)
视图.py:
class WorkLogListView(FlowListMixin, ListView):
model = WorkLog
class WorkLogCreateView(FlowMixin, CreateView):
model = WorkLog
fields = '__all__'
流.py:
from .views import WorkLogCreateView
from .models import TicketProcess
@frontend.register
class TicketFlow(Flow):
process_class = TicketProcess
start = (
flow.Start(
CreateProcessView,
fields = ['title', 'category', 'description', 'planned']
).Permission(
auto_create=True
).Next(this.resolution)
)
add_worklog = (
flow.View(
WorkLogListView
).Permission(
auto_create=True
).Next(this.end)
)
end = flow.End()