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

Adding new state/transition to existing objects #55

Closed I-NOZex closed 5 years ago

I-NOZex commented 7 years ago

In my workflow, I wanted to add a new state/transition, and I'm getting the available proceedings through get_available_proceedings method, but the old objects don't show the new created transition, only shows in new records. Is it supposed? There is a way to "update" or "rebuild" in order to show the new transition in old objects?

Thanks in advance

I-NOZex commented 7 years ago

@javrasya

Intey commented 6 years ago

Yes, it's possible.

from river.services.proceeding import ProceedingService
from yourapp.models import ModelWithState
obj = ModelWithState.objects.first()  # get first object for example. You need to do this with each instance
ProceedingService.init_proceedings(obj)

After this, you get available transition.

javrasya commented 5 years ago

@I-NOZex, Sorry for the very late response. I have just released v1.0.0 and reviewing all the issues.

First of all, this is a very complicated situation.

Maybe adding a new transition is not hard to handle but if this was allowed by django-river, then django-river would have to support all other modifications like an update and delete as well in the workflow. As you may guess, it is turning out to be hard to manage. This is why this has never been an intention to support modifications in the workflow and have it applied for already existing objects. But new objects will definetly will apply your new workflow definition.

But if you really need it for adding so, you can use @Intey's way. It will ensure that your workflow changes for addings are applied. In the new version of django-river, it looks like this;

obj.river.your_state_field_name.initialize_approvals()