mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #18454 -- Added ability to pass a list of signals to receiver.
Added ability to use receiver decorator in the following way:
@receiver([post_save, post_delete], sender=MyModel)
def signals_receiver(sender, **kwargs):
...
This commit is contained in:
committed by
Florian Apolloner
parent
946d3d9f84
commit
d4da08375b
@@ -103,6 +103,9 @@ Django 1.5 also includes several smaller improvements worth noting:
|
||||
* In the localflavor for Canada, "pq" was added to the acceptable codes for
|
||||
Quebec. It's an old abbreviation.
|
||||
|
||||
* The :ref:`receiver <connecting-receiver-functions>` decorator is now able to
|
||||
connect to more than one signal by supplying a list of signals.
|
||||
|
||||
Backwards incompatible changes in 1.5
|
||||
=====================================
|
||||
|
||||
|
||||
@@ -52,10 +52,10 @@ called when the signal is sent by using the
|
||||
:meth:`.Signal.connect` method:
|
||||
|
||||
.. method:: Signal.connect(receiver, [sender=None, weak=True, dispatch_uid=None])
|
||||
|
||||
|
||||
:param receiver: The callback function which will be connected to this
|
||||
signal. See :ref:`receiver-functions` for more information.
|
||||
|
||||
|
||||
:param sender: Specifies a particular sender to receive signals from. See
|
||||
:ref:`connecting-to-specific-signals` for more information.
|
||||
|
||||
@@ -129,10 +129,17 @@ receiver:
|
||||
|
||||
Now, our ``my_callback`` function will be called each time a request finishes.
|
||||
|
||||
Note that ``receiver`` can also take a list of signals to connect a function
|
||||
to.
|
||||
|
||||
.. versionadded:: 1.3
|
||||
|
||||
The ``receiver`` decorator was added in Django 1.3.
|
||||
|
||||
.. versionchanged:: 1.5
|
||||
|
||||
The ability to pass a list of signals was added.
|
||||
|
||||
.. admonition:: Where should this code live?
|
||||
|
||||
You can put signal handling and registration code anywhere you like.
|
||||
@@ -182,7 +189,7 @@ Preventing duplicate signals
|
||||
In some circumstances, the module in which you are connecting signals may be
|
||||
imported multiple times. This can cause your receiver function to be
|
||||
registered more than once, and thus called multiples times for a single signal
|
||||
event.
|
||||
event.
|
||||
|
||||
If this behavior is problematic (such as when using signals to
|
||||
send an email whenever a model is saved), pass a unique identifier as
|
||||
|
||||
Reference in New Issue
Block a user