0

我正在为我的公司制定一个流程。这样做我发现有必要存储正在插入过程中的数据。我的流程运行良好,但不是保存在我的其他模型中,而是继续将数据保存在与流程相对应的表上,而不是我的其他模型中。

模型.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,但不会保存在我的另一个表上。

4

1 回答 1

0

CreateProcessViewDjango Viewflow中的所有流程视图UpdateProcessView都连接到流程模型。这意味着视图和流程可以跟踪与从Process模型继承时添加的流程相关的元数据。

在这种情况下,您尝试将 a 设置为UpdateProcessViewRevisiones继承自Process但只是普通的模型models.Model

您试图通过指定错误地设置它,model=Revisiones但是如果您打开UpdateProcessView该类,您将看到以下代码:

@property
def model(self):
    """Process class."""
    return self.activation.flow_class.process_class

如您所见,模型始终设置为 Flow 的 Process 类。

相反,您要做的是以Revisiones其他方式设置数据。也许您在流程中创建了一个处理程序,该处理程序根据流程数据设置此数据,或者您可能为form_valid您编写自定义逻辑以存储这些内容的其他 View 方法创建覆盖方法。

于 2019-02-19T16:42:06.600 回答