Skip to content

Commit ca5dfe6

Browse files
committed
Enable lazy senders by inheriting ModelSignal
1 parent ff12c88 commit ca5dfe6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

django_fsm/signals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from django.dispatch import Signal
3+
from django.db.models.signals import ModelSignal
44

5-
pre_transition = Signal()
6-
post_transition = Signal()
5+
pre_transition = ModelSignal()
6+
post_transition = ModelSignal()

tests/testapp/tests/test_basic_transitions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ def test_signals_not_called_on_invalid_transition(self):
152152
assert not self.post_transition_called
153153

154154

155+
class LazySenderTests(StateSignalsTests):
156+
def setUp(self):
157+
self.model = SimpleBlogPost()
158+
self.pre_transition_called = False
159+
self.post_transition_called = False
160+
pre_transition.connect(self.on_pre_transition, sender="testapp.SimpleBlogPost")
161+
post_transition.connect(self.on_post_transition, sender="testapp.SimpleBlogPost")
162+
163+
155164
class TestFieldTransitionsInspect(TestCase):
156165
def setUp(self):
157166
self.model = SimpleBlogPost()

0 commit comments

Comments
 (0)