Git Product home page Git Product logo

Comments (8)

xavella avatar xavella commented on June 1, 2024 2

Our solution was a post transition signal to save the new state upon successful state change:

from django_fsm.signals import post_transition

@receiver(post_transition, sender=models.MyModel)
def save_new_workflow_state(sender, instance, name, source, target, **kwargs):
    """ Save the new workflow state following successful django_fsm transition. """

    if source != target:
        instance.save()

from django-fsm.

kmmbvnr avatar kmmbvnr commented on June 1, 2024

Yep, it was removed in 2014 with django-fsm 2.0 release.

The recommended way for today is to switch to django-viewflow==2.0.0a and explicitly define desired behavior with .on_success decorator - https://docs-next.viewflow.io/fsm/models.html

from django-fsm.

ddahan avatar ddahan commented on June 1, 2024

What is the recommandation if we want to stick with django-fsm package?

from django-fsm.

ddahan avatar ddahan commented on June 1, 2024

@xavella thanks for sharing! Is there a way to write this once for all models?
I can already see a new developer joining our codebase, adding a new Django Model and asking "why my model is not saved"? :)

from django-fsm.

xavella avatar xavella commented on June 1, 2024

I wouldn't take that approach as it would also apply to the admin models, which I don't see any reason to restrict track. How many models?

from django-fsm.

ddahan avatar ddahan commented on June 1, 2024

I'm not sure to understand the issue with admin models, as only my custom models have FSMField and transitions configured (except if a package is using django-fsm behind the scene ?).

Lots of models (more than 10) will need transitions. If I can do it, I'd like to avoid the manual step to add a signal for each of them, as it could be error-prone, and it's not DRY.

from django-fsm.

xavella avatar xavella commented on June 1, 2024

I would do this long-hand, not sure how to abstract the signal but maybe there is a way.

from django-fsm.

ddahan avatar ddahan commented on June 1, 2024

it seems ok following these steps:

  • removing the sender parameter from within the decorator (means all senders are accepted)
  • moving the signal to signals.py into my app
  • importing it using the ready() method

from django-fsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.