Search code examples
djangodjango-viewflow

designing models in django-viewflow


I am new to django-viewflow and still going through the viewflow related documents including cook-book examples.

In the project that I am working on, I have below models.

class FirstModel(models.Model):
    prod_ref_num = models.IntegerField()
    prod_part_num = models.IntegerField()

The above model FirstModel is being updated by external process

class SecondModel(models.Model):
     prod_type = models.CharField(max_length=30)
     prod_category = models.CharField(max_length=30)         
     approved = models.BooleanField(default=False)

The above model SecondModel is part of the work flow which is mentioned as below).

  1. During start of the flow, it should allow to take inputs for prod_type and prod_category and it should execute SQL query (for external data source) using data entered for prod_type and prod_category. The query result should be presented for the user using django_tables2). Based on the query result, user can proceed or cancel the flow.
  2. If proceed, it transitions to approval flow.
  3. If cancel, data shouldnt get inserted into model Product2.

Can you please provide insights on how the models can be designed in django-viewflow ?

Also how the work flow process can be implemented especially executing SQL and diplaying query results using django_tables2.


Solution

  • Viewflow provides the workflow layer on top of django views, extracts flow logic, and allows to keep view code independent from the flow.

    You can design your django views and models, as usual, just implement them as independent steps, use @flow_view decorator to initialize request.actiovation and call activation.done() as soon as a task complete.

    You can keep your models separated from the viewflow process model, just put a foreign key in a process model to your model.

    You can check the shipment demo, for the sample.

    https://github.com/viewflow/viewflow/blob/master/demo/shipment/models.py#L63

    Update: You can also check the Article - data management in Viewflow https://docs.viewflow.io/workflow/data_flow.html