javrasya / django-river

Django workflow library that supports on the fly changes ⛵
BSD 3-Clause "New" or "Revised" License
742 stars 105 forks source link

Generating Workflow History #87

Closed rupin closed 5 years ago

rupin commented 5 years ago

If I had access to a model object, how can i know everything about the workflow? Can i access information about the workflow, specifically its history.

The API documentation talks about the current state, but more often than not, people will want to read a summary.

rupin commented 5 years ago

So table river_transitionapproval is tracking the history. It is definitely very convenient that all states are there whenever a new flow is created. My understanding is when a stage in a flow is completed, its status flag is changed from 0->1 and a timestamp is added in the action_date column. The object_id column holds the reference to the primary key of the model in which the statefield has been added.

Can this table be serialized for consumption through an API?

javrasya commented 5 years ago

This is about right. You can use it to track history as well.

I am not really sure why you need it and what you mean by "through an API" to be honest but it is yet another Django model, you can do anything that you can do with other Django models.

rupin commented 5 years ago

I started to build views with the django rest framework. I did that for the State table and got a weird result. My serializer is as follows

from river.models import State
from rest_framework import serializers

class StateSerializer(serializers.Serializer):

    class Meta:
        model = State
        fields = ['id', 'label']

Also, my API view is as follows

from rest_framework import generics
from workflowengine.riverserializers.StateSerializer import StateSerializer
from river.models import State

class StateList(generics.ListAPIView):  

    serializer_class = StateSerializer
    def get_queryset(self):
        return State.objects.all() 

Through the Admin console, I have added 11 states inside my state table, which I have checked with pgadmin.

When i access the API through the browser, I get 11 empty sections in my API ( no error, just the data is missing).

jEUMT

I cant seem to understand how the 11 data points presented in the API are empty. That it presented 11 elements, but no data, which is pretty weird.

javrasya commented 5 years ago

It has been quite a while since I last worked with django rest framework, but this seems to be a problem with the way you configured it with django rest framework. Because State is yet another django model with no specialty.

javrasya commented 5 years ago

I think you should use serializers.ModelSerializer instead of serializers.Serializer

rupin commented 5 years ago

oh yeah! that worked!