我正在为我的公司制定一个流程。这样做我发现有必要存储正在插入过程中的数据。我的流程运行良好,但不是保存在我的其他模型中,而是继续将数据保存在与流程相对应的表上,而不是我的其他模型中。
模型.py:
from __future__ import unicode_literals
from datetime import datetime
from django.db import models
from viewflow.models import Process
from django.contrib.auth.models import User
class DeliveryProcess(Process):
#### Asignador ###
nombre_del_entregable= models.CharField(max_length=150)
fecha_inicio=models.DateField(auto_now_add=False, default=datetime.now)
fecha_de_terminacion=models.DateField(auto_now=False, default=datetime.now)
ejecutor=models.ForeignKey(User,on_delete=models.CASCADE, null=True, related_name='+')
observaciones_asignador=models.TextField()
##### Ejecutor #####
echa_de_ejecucion=models.DateField(auto_now_add=False, default=datetime.now)
oberservaciones_ejecutor=models.TextField()
finalizado= models.BooleanField(default=False)
revisor=models.ForeignKey(User,on_delete=models.CASCADE, null=True, related_name='+')
aprobacion_final= models.BooleanField(default=False)
anadir_revisor= models.BooleanField(default=False)
##### Revisor #####
# aprobacion_final= models.BooleanField(default=False)
# anadir_revisor= models.BooleanField(default=False)
# nuevo_revisor= models.ForeignKey(
# User,on_delete=models.CASCADE, null=True, related_name='+')
# obserservaciones_revisor= models.TextField()
class Revisiones(models.Model):
id_revision= models.AutoField(primary_key=True)
fecha_de_revision=models.DateField(auto_now_add=False, default=datetime.now)
revisor=models.ForeignKey(User,on_delete=models.CASCADE, null=True, related_name='+')
aprobacion_final= models.BooleanField(default=False)
anadir_revisor= models.BooleanField(default=False)
observaciones_revisor= models.TextField()
流.py:
from __future__ import unicode_literals
from viewflow import flow
from viewflow.base import this, Flow
from viewflow.flow.views import CreateProcessView, UpdateProcessView
from viewflow.lock import select_for_update_lock
from .models import DeliveryProcess
from viewflow import frontend
from . import views
@frontend.register
class Delivery_flow(Flow):
process_class = DeliveryProcess
start = (
flow.Start(
CreateProcessView,
fields=["nombre_del_entregable", "fecha_inicio", 'fecha_de_terminacion', 'ejecutor','observaciones_asignador']
).Next(this.ejecutar)
)
ejecutar = (
flow.View(
UpdateProcessView,
fields=["fecha_de_ejecucion", "oberservaciones_ejecutor", "finalizado","revisor"],
task_description="Ejecutar"
).Assign(lambda act: act.process.ejecutor
).Next(this.revisor_check)
)
revisor_check = (
flow.View(
views.ReView,
fields=["aprobacion_final",'anadir_revisor',"revisor",'observaciones_revisor', 'fecha_de_revision']
).Assign(lambda act: act.process.revisor)
.Next(this.split)
)
split =(
#If(lambda activation: activation.process.aprobacion_final)
flow.Switch()
.Case(this.end, cond=(lambda act: act.process.aprobacion_final))
.Case(this.revisor_check, cond=(lambda act: act.process.anadir_revisor))
.Case(this.ejecutar, cond=(not(lambda act: act.process.aprobacion_finale) and (lambda act: act.process.anadir_revisor)))
)
end = flow.End()
def send_hello_world_request(self, activation):
print(activation.process.text)
视图.py:
from django.shortcuts import render
from django.views import generic
from viewflow.flow.views import CreateProcessView, UpdateProcessView
from .models import Revisiones
from viewflow.decorators import flow_start_view, flow_view
from viewflow.flow.views import StartFlowMixin, FlowViewMixin
class ReView(UpdateProcessView):
model = Revisiones
fields = ['revisor', 'observaciones_revisor']
我想保存数据的模型是“Revisiones”,我使用的自定义视图是 ReView,但不会保存在我的另一个表上。