Designing a a system which needs state transitions of a model which are based on transitions of other models.
I'm using Django FSM
Example:
class Foo(models.Model):
baz = models.Charfield()
state = FSMField(default='new')
class Bar(models.Model):
x = models.CharField()
state = FSMField(default='draft')
foo = models.ForeignKey(Foo)
Use Case:
Foo can have the following states - new, draft, complete, pending_approval, approved Foo can have multiple Bars
Bar can have the following states - draft, complete
Foo should move to complete automatically when all Bar's are complete, how can this be achieved
I don't know django-fsm at all, but with a quick look at the documentation there is a
post_transitionsignal which is triggered after an instance changes its state. So you could define one that listens to Bar, then checks that the instance's Foo object has only completed Bars. Something like: