diff options
| author | Brian Rosner <brosner@gmail.com> | 2010-09-12 19:58:05 +0000 |
|---|---|---|
| committer | Brian Rosner <brosner@gmail.com> | 2010-09-12 19:58:05 +0000 |
| commit | b7f60045fe9e662c8c53a6f7b4e2c410830d5b29 (patch) | |
| tree | 804ff0e8df2e8d5b02a1c06c8a534fe44943b2de /docs | |
| parent | 030c97b119bea450cc4e1f289a95e91aa664221c (diff) | |
Fixed #9015 -- added a signal decorator for simplifying signal connections
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13773 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/signals.txt | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/docs/topics/signals.txt b/docs/topics/signals.txt index 35dc3f4c09..78790db071 100644 --- a/docs/topics/signals.txt +++ b/docs/topics/signals.txt @@ -80,7 +80,8 @@ must be able to handle those new arguments. Connecting receiver functions ----------------------------- -Next, we'll need to connect our receiver to the signal: +There are two ways you can connect a receiever to a signal. You can take the +manual connect route: .. code-block:: python @@ -88,6 +89,17 @@ Next, we'll need to connect our receiver to the signal: request_finished.connect(my_callback) +Alternatively, you can use a decorator used when you define your receiver: + +.. code-block:: python + + from django.core.signals import request_finished + from django.dispatch import receiver + + @receiver(request_finished) + def my_callback(sender, **kwargs): + print "Request finished!" + Now, our ``my_callback`` function will be called each time a request finishes. .. admonition:: Where should this code live? @@ -115,13 +127,13 @@ signals sent by some model: .. code-block:: python from django.db.models.signals import pre_save + from django.dispatch import receiver from myapp.models import MyModel + @receiver(pre_save, sender=MyModel) def my_handler(sender, **kwargs): ... - pre_save.connect(my_handler, sender=MyModel) - The ``my_handler`` function will only be called when an instance of ``MyModel`` is saved. |
