diff options
Diffstat (limited to 'django/dispatch/dispatcher.py')
-rw-r--r-- | django/dispatch/dispatcher.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py index de09334637..c4516d88b0 100644 --- a/django/dispatch/dispatcher.py +++ b/django/dispatch/dispatcher.py @@ -235,3 +235,19 @@ class Signal(object): for idx, (r_key, _) in enumerate(self.receivers): if r_key == key: del self.receivers[idx] + + +def receiver(signal, **kwargs): + """ + A decorator for connecting receivers to signals. Used by passing in the + signal and keyword arguments to connect:: + + @receiver(post_save, sender=MyModel) + def signal_receiver(sender, **kwargs): + ... + + """ + def _decorator(func): + signal.connect(func, **kwargs) + return func + return _decorator |