Git Product home page Git Product logo

Comments (4)

enilsen16 avatar enilsen16 commented on May 23, 2024

Just saw that there is discussions in GH now, lmk if you'd rather have me ask there. Thanks!

from python-statemachine.

fgmacedo avatar fgmacedo commented on May 23, 2024

Hi @enilsen16 ,

This state_field constructor parameter is required in order to the state machine knows the Django's model field that holds the state value.

Can you provide more context on why you're passing this value? Understanding the underlying needs may help to suggest alternative implementation.

The Mixin creates an instance of the State machine automatically, and passes the model instance as the target object that will hold the state value, and the model's state field. As this is done automatically for you, you'll have a hard time to change the initialization behavior.

See how the mixin creates a StateMachine instance: https://github.com/fgmacedo/python-statemachine/blob/develop/statemachine/mixins.py#L38

            machine_cls(selfstate_field=self.state_field_name),

So, trying to actually answer your question, you don't need to pass an additional model value to the state machine to use as condition, all model attributes, properties and methods are available by default.

See this example: https://python-statemachine.readthedocs.io/en/latest/auto_examples/order_control_rich_model_machine.html#sphx-glr-auto-examples-order-control-rich-model-machine-py

The SM uses payment_received, that is an attribute of the model.

process_order = processing.to(shipping, cond="payment_received")

This is possible due to the v1.0 new observer implementation: https://python-statemachine.readthedocs.io/en/latest/observers.html

The model is registered as an observer, so you can implement callbacks, conditions, virtually any state/transition hook on the model.

Hope that this helps, let me know if works for you so we can close the issue.

Best regards!

from python-statemachine.

fgmacedo avatar fgmacedo commented on May 23, 2024

from python-statemachine.

fgmacedo avatar fgmacedo commented on May 23, 2024

Closing as an alternative implementation using the model without the need to pass additional parameters to the SM constructor. Docs improved at #352.

Feel free to reopen if something is missing.

from python-statemachine.

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.