Comments (4)
Just saw that there is discussions in GH now, lmk if you'd rather have me ask there. Thanks!
from python-statemachine.
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(self, state_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.
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.
- AI: Improve the docs mentioning that the model, if passed, is also registered as an observer: https://python-statemachine.readthedocs.io/en/latest/observers.html
from python-statemachine.
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)
- feature request: async callbacks HOT 3
- Incompatible with spy wrapper from pytest-mock HOT 3
- Add automation (GH action) to publish a new version on pypi HOT 1
- Simple question HOT 10
- Generate the code from PlantUML diagrams HOT 2
- Type annotations missing for `initial_state` and `final_states`; leading to linting errors with Pylint/Pyright HOT 3
- Expensive instantiation of StateMachine HOT 3
- AttributeError: object has no attribute 'model' HOT 3
- Enable Multithreading HOT 2
- [Feature request] State machine based workflow for database storage on entity state tracking HOT 1
- Action callback gets called twice when mixing definition methods HOT 1
- Check that all state transitions can reach a final state. HOT 6
- Execute a state machine from another state machine HOT 1
- Guards and conditions passed as strings really necessary? HOT 6
- ROS2, state transition not possible HOT 2
- Send a state machine over MQTT / serializing-deserializing a SM HOT 6
- Question: How can I use cond functions to gatekeep, but not fail? HOT 5
- Failed to generate a graphic image HOT 2
- Models instantiated in Djangos setUpTestData seem to skip conditions HOT 5
- @<transition>.cond decorator bug, general question about running code on every transition even if TransitionNotAllowed is raised HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-statemachine.