You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
[review] -> active <--> paused
| | |
| v |
\------> deleted <------/
review is the initial state.
Now I noticed, that both .save and __init__ of my model allow direct creation with states that are not review, not the default/initial state. There is custom code similar to this, to enforce that behavior:
def _deny_creation_with_non_initial_state(self):
if self.pk is None and self.status == ............:
raise TransitionNotAllowed()
def save(self, **kwargs):
self._deny_creation_with_non_initial_state()
super().save(**kwargs)
I have a feeling though that my approach is more complicated than necessary. Is there a way to add transitions from before existence to object creation a la source=None, target='review' or so? Any ideas?
Thanks!
The text was updated successfully, but these errors were encountered:
I've used django-fsm in a few projects and also had this question about how I can enforce new objects to be created with a particular status. @moseb your code seems like a decent solution, but it would be great if django-fsm provided a nice way to enforce this.
Hi!
I have an FSM that looks like this
review
is the initial state.Now I noticed, that both
.save
and__init__
of my model allow direct creation with states that are notreview
, not the default/initial state. There is custom code similar to this, to enforce that behavior:I have a feeling though that my approach is more complicated than necessary. Is there a way to add transitions from before existence to object creation a la
source=None, target='review'
or so? Any ideas?Thanks!
The text was updated successfully, but these errors were encountered: