1. =======
    
  2. Signals
    
  3. =======
    
  4. 
    
  5. A list of all the signals that Django sends. All built-in signals are sent
    
  6. using the :meth:`~django.dispatch.Signal.send` method.
    
  7. 
    
  8. .. seealso::
    
  9. 
    
  10.     See the documentation on the :doc:`signal dispatcher </topics/signals>` for
    
  11.     information regarding how to register for and receive signals.
    
  12. 
    
  13.     The :doc:`authentication framework </topics/auth/index>` sends :ref:`signals when
    
  14.     a user is logged in / out <topics-auth-signals>`.
    
  15. 
    
  16. Model signals
    
  17. =============
    
  18. 
    
  19. .. module:: django.db.models.signals
    
  20.    :synopsis: Signals sent by the model system.
    
  21. 
    
  22. The :mod:`django.db.models.signals` module defines a set of signals sent by the
    
  23. model system.
    
  24. 
    
  25. .. warning::
    
  26. 
    
  27.     Signals can make your code harder to maintain. Consider implementing a
    
  28.     helper method on a :ref:`custom manager <custom-managers>`, to
    
  29.     both update your models and perform additional logic, or else
    
  30.     :ref:`overriding model methods <overriding-model-methods>` before using
    
  31.     model signals.
    
  32. 
    
  33. .. warning::
    
  34. 
    
  35.     Many of these signals are sent by various model methods like
    
  36.     ``__init__()`` or :meth:`~django.db.models.Model.save` that you can
    
  37.     override in your own code.
    
  38. 
    
  39.     If you override these methods on your model, you must call the parent class'
    
  40.     methods for these signals to be sent.
    
  41. 
    
  42.     Note also that Django stores signal handlers as weak references by default,
    
  43.     so if your handler is a local function, it may be garbage collected.  To
    
  44.     prevent this, pass ``weak=False`` when you call the signal's :meth:`~django.dispatch.Signal.connect`.
    
  45. 
    
  46. .. note::
    
  47. 
    
  48.     Model signals ``sender`` model can be lazily referenced when connecting a
    
  49.     receiver by specifying its full application label. For example, an
    
  50.     ``Question`` model defined in the ``polls`` application could be referenced
    
  51.     as ``'polls.Question'``. This sort of reference can be quite handy when
    
  52.     dealing with circular import dependencies and swappable models.
    
  53. 
    
  54. ``pre_init``
    
  55. ------------
    
  56. 
    
  57. .. attribute:: django.db.models.signals.pre_init
    
  58.    :module:
    
  59. 
    
  60. .. ^^^^^^^ this :module: hack keeps Sphinx from prepending the module.
    
  61. 
    
  62. Whenever you instantiate a Django model, this signal is sent at the beginning
    
  63. of the model's ``__init__()`` method.
    
  64. 
    
  65. Arguments sent with this signal:
    
  66. 
    
  67. ``sender``
    
  68.     The model class that just had an instance created.
    
  69. 
    
  70. ``args``
    
  71.     A list of positional arguments passed to ``__init__()``.
    
  72. 
    
  73. ``kwargs``
    
  74.     A dictionary of keyword arguments passed to ``__init__()``.
    
  75. 
    
  76. For example, the :doc:`tutorial </intro/tutorial02>` has this line::
    
  77. 
    
  78.     q = Question(question_text="What's new?", pub_date=timezone.now())
    
  79. 
    
  80. The arguments sent to a :data:`pre_init` handler would be:
    
  81. 
    
  82. ==========  ===============================================================
    
  83. Argument    Value
    
  84. ==========  ===============================================================
    
  85. ``sender``  ``Question`` (the class itself)
    
  86. 
    
  87. ``args``    ``[]`` (an empty list because there were no positional
    
  88.             arguments passed to ``__init__()``)
    
  89. 
    
  90. ``kwargs``  ``{'question_text': "What's new?",``
    
  91.             ``'pub_date': datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=datetime.timezone.utc)}``
    
  92. ==========  ===============================================================
    
  93. 
    
  94. ``post_init``
    
  95. -------------
    
  96. 
    
  97. .. data:: django.db.models.signals.post_init
    
  98.    :module:
    
  99. 
    
  100. Like pre_init, but this one is sent when the ``__init__()`` method finishes.
    
  101. 
    
  102. Arguments sent with this signal:
    
  103. 
    
  104. ``sender``
    
  105.     As above: the model class that just had an instance created.
    
  106. 
    
  107. ``instance``
    
  108.     The actual instance of the model that's just been created.
    
  109. 
    
  110.     .. note::
    
  111. 
    
  112.         :attr:`instance._state <django.db.models.Model._state>` isn't set
    
  113.         before sending the ``post_init`` signal, so ``_state`` attributes
    
  114.         always have their default values. For example, ``_state.db`` is
    
  115.         ``None``.
    
  116. 
    
  117. .. warning::
    
  118. 
    
  119.     For performance reasons, you shouldn't perform queries in receivers of
    
  120.     ``pre_init`` or ``post_init`` signals because they would be executed for
    
  121.     each instance returned during queryset iteration.
    
  122. 
    
  123. ``pre_save``
    
  124. ------------
    
  125. 
    
  126. .. data:: django.db.models.signals.pre_save
    
  127.    :module:
    
  128. 
    
  129. This is sent at the beginning of a model's :meth:`~django.db.models.Model.save`
    
  130. method.
    
  131. 
    
  132. Arguments sent with this signal:
    
  133. 
    
  134. ``sender``
    
  135.     The model class.
    
  136. 
    
  137. ``instance``
    
  138.     The actual instance being saved.
    
  139. 
    
  140. ``raw``
    
  141.     A boolean; ``True`` if the model is saved exactly as presented
    
  142.     (i.e. when loading a fixture). One should not query/modify other
    
  143.     records in the database as the database might not be in a
    
  144.     consistent state yet.
    
  145. 
    
  146. ``using``
    
  147.     The database alias being used.
    
  148. 
    
  149. ``update_fields``
    
  150.     The set of fields to update as passed to :meth:`.Model.save`, or ``None``
    
  151.     if ``update_fields`` wasn't passed to ``save()``.
    
  152. 
    
  153. ``post_save``
    
  154. -------------
    
  155. 
    
  156. .. data:: django.db.models.signals.post_save
    
  157.    :module:
    
  158. 
    
  159. Like :data:`pre_save`, but sent at the end of the
    
  160. :meth:`~django.db.models.Model.save` method.
    
  161. 
    
  162. Arguments sent with this signal:
    
  163. 
    
  164. ``sender``
    
  165.     The model class.
    
  166. 
    
  167. ``instance``
    
  168.     The actual instance being saved.
    
  169. 
    
  170. ``created``
    
  171.     A boolean; ``True`` if a new record was created.
    
  172. 
    
  173. ``raw``
    
  174.     A boolean; ``True`` if the model is saved exactly as presented
    
  175.     (i.e. when loading a fixture). One should not query/modify other
    
  176.     records in the database as the database might not be in a
    
  177.     consistent state yet.
    
  178. 
    
  179. ``using``
    
  180.     The database alias being used.
    
  181. 
    
  182. ``update_fields``
    
  183.     The set of fields to update as passed to :meth:`.Model.save`, or ``None``
    
  184.     if ``update_fields`` wasn't passed to ``save()``.
    
  185. 
    
  186. ``pre_delete``
    
  187. --------------
    
  188. 
    
  189. .. data:: django.db.models.signals.pre_delete
    
  190.    :module:
    
  191. 
    
  192. Sent at the beginning of a model's :meth:`~django.db.models.Model.delete`
    
  193. method and a queryset's :meth:`~django.db.models.query.QuerySet.delete` method.
    
  194. 
    
  195. Arguments sent with this signal:
    
  196. 
    
  197. ``sender``
    
  198.     The model class.
    
  199. 
    
  200. ``instance``
    
  201.     The actual instance being deleted.
    
  202. 
    
  203. ``using``
    
  204.     The database alias being used.
    
  205. 
    
  206. ``origin``
    
  207.     .. versionadded:: 4.1
    
  208. 
    
  209.     The origin of the deletion being the instance of a ``Model`` or
    
  210.     ``QuerySet`` class.
    
  211. 
    
  212. ``post_delete``
    
  213. ---------------
    
  214. 
    
  215. .. data:: django.db.models.signals.post_delete
    
  216.    :module:
    
  217. 
    
  218. Like :data:`pre_delete`, but sent at the end of a model's
    
  219. :meth:`~django.db.models.Model.delete` method and a queryset's
    
  220. :meth:`~django.db.models.query.QuerySet.delete` method.
    
  221. 
    
  222. Arguments sent with this signal:
    
  223. 
    
  224. ``sender``
    
  225.     The model class.
    
  226. 
    
  227. ``instance``
    
  228.     The actual instance being deleted.
    
  229. 
    
  230.     Note that the object will no longer be in the database, so be very
    
  231.     careful what you do with this instance.
    
  232. 
    
  233. ``using``
    
  234.     The database alias being used.
    
  235. 
    
  236. ``origin``
    
  237.     .. versionadded:: 4.1
    
  238. 
    
  239.     The origin of the deletion being the instance of a ``Model`` or
    
  240.     ``QuerySet`` class.
    
  241. 
    
  242. ``m2m_changed``
    
  243. ---------------
    
  244. 
    
  245. .. data:: django.db.models.signals.m2m_changed
    
  246.    :module:
    
  247. 
    
  248. Sent when a :class:`~django.db.models.ManyToManyField` is changed on a model
    
  249. instance. Strictly speaking, this is not a model signal since it is sent by the
    
  250. :class:`~django.db.models.ManyToManyField`, but since it complements the
    
  251. :data:`pre_save`/:data:`post_save` and :data:`pre_delete`/:data:`post_delete`
    
  252. when it comes to tracking changes to models, it is included here.
    
  253. 
    
  254. Arguments sent with this signal:
    
  255. 
    
  256. ``sender``
    
  257.     The intermediate model class describing the
    
  258.     :class:`~django.db.models.ManyToManyField`. This class is automatically
    
  259.     created when a many-to-many field is defined; you can access it using the
    
  260.     ``through`` attribute on the many-to-many field.
    
  261. 
    
  262. ``instance``
    
  263.     The instance whose many-to-many relation is updated. This can be an
    
  264.     instance of the ``sender``, or of the class the
    
  265.     :class:`~django.db.models.ManyToManyField` is related to.
    
  266. 
    
  267. ``action``
    
  268.     A string indicating the type of update that is done on the relation.
    
  269.     This can be one of the following:
    
  270. 
    
  271.     ``"pre_add"``
    
  272.         Sent *before* one or more objects are added to the relation.
    
  273.     ``"post_add"``
    
  274.         Sent *after* one or more objects are added to the relation.
    
  275.     ``"pre_remove"``
    
  276.         Sent *before* one or more objects are removed from the relation.
    
  277.     ``"post_remove"``
    
  278.         Sent *after* one or more objects are removed from the relation.
    
  279.     ``"pre_clear"``
    
  280.         Sent *before* the relation is cleared.
    
  281.     ``"post_clear"``
    
  282.         Sent *after* the relation is cleared.
    
  283. 
    
  284. ``reverse``
    
  285.     Indicates which side of the relation is updated (i.e., if it is the
    
  286.     forward or reverse relation that is being modified).
    
  287. 
    
  288. ``model``
    
  289.     The class of the objects that are added to, removed from or cleared
    
  290.     from the relation.
    
  291. 
    
  292. ``pk_set``
    
  293.     For the ``pre_add`` and ``post_add`` actions, this is a set of primary key
    
  294.     values that will be, or have been, added to the relation. This may be a
    
  295.     subset of the values submitted to be added, since inserts must filter
    
  296.     existing values in order to avoid a database ``IntegrityError``.
    
  297. 
    
  298.     For the ``pre_remove`` and ``post_remove`` actions, this is a set of
    
  299.     primary key values that was submitted to be removed from the relation. This
    
  300.     is not dependent on whether the values actually will be, or have been,
    
  301.     removed. In particular, non-existent values may be submitted, and will
    
  302.     appear in ``pk_set``, even though they have no effect on the database.
    
  303. 
    
  304.     For the ``pre_clear`` and ``post_clear`` actions, this is ``None``.
    
  305. 
    
  306. ``using``
    
  307.     The database alias being used.
    
  308. 
    
  309. For example, if a ``Pizza`` can have multiple ``Topping`` objects, modeled
    
  310. like this::
    
  311. 
    
  312.     class Topping(models.Model):
    
  313.         # ...
    
  314.         pass
    
  315. 
    
  316.     class Pizza(models.Model):
    
  317.         # ...
    
  318.         toppings = models.ManyToManyField(Topping)
    
  319. 
    
  320. If we connected a handler like this::
    
  321. 
    
  322.     from django.db.models.signals import m2m_changed
    
  323. 
    
  324.     def toppings_changed(sender, **kwargs):
    
  325.         # Do something
    
  326.         pass
    
  327. 
    
  328.     m2m_changed.connect(toppings_changed, sender=Pizza.toppings.through)
    
  329. 
    
  330. and then did something like this::
    
  331. 
    
  332.     >>> p = Pizza.objects.create(...)
    
  333.     >>> t = Topping.objects.create(...)
    
  334.     >>> p.toppings.add(t)
    
  335. 
    
  336. the arguments sent to a :data:`m2m_changed` handler (``toppings_changed`` in
    
  337. the example above) would be:
    
  338. 
    
  339. ==============  ============================================================
    
  340. Argument        Value
    
  341. ==============  ============================================================
    
  342. ``sender``      ``Pizza.toppings.through`` (the intermediate m2m class)
    
  343. 
    
  344. ``instance``    ``p`` (the ``Pizza`` instance being modified)
    
  345. 
    
  346. ``action``      ``"pre_add"`` (followed by a separate signal with ``"post_add"``)
    
  347. 
    
  348. ``reverse``     ``False`` (``Pizza`` contains the
    
  349.                 :class:`~django.db.models.ManyToManyField`, so this call
    
  350.                 modifies the forward relation)
    
  351. 
    
  352. ``model``       ``Topping`` (the class of the objects added to the
    
  353.                 ``Pizza``)
    
  354. 
    
  355. ``pk_set``      ``{t.id}`` (since only ``Topping t`` was added to the relation)
    
  356. 
    
  357. ``using``       ``"default"`` (since the default router sends writes here)
    
  358. ==============  ============================================================
    
  359. 
    
  360. And if we would then do something like this::
    
  361. 
    
  362.     >>> t.pizza_set.remove(p)
    
  363. 
    
  364. the arguments sent to a :data:`m2m_changed` handler would be:
    
  365. 
    
  366. ==============  ============================================================
    
  367. Argument        Value
    
  368. ==============  ============================================================
    
  369. ``sender``      ``Pizza.toppings.through`` (the intermediate m2m class)
    
  370. 
    
  371. ``instance``    ``t`` (the ``Topping`` instance being modified)
    
  372. 
    
  373. ``action``      ``"pre_remove"`` (followed by a separate signal with ``"post_remove"``)
    
  374. 
    
  375. ``reverse``     ``True`` (``Pizza`` contains the
    
  376.                 :class:`~django.db.models.ManyToManyField`, so this call
    
  377.                 modifies the reverse relation)
    
  378. 
    
  379. ``model``       ``Pizza`` (the class of the objects removed from the
    
  380.                 ``Topping``)
    
  381. 
    
  382. ``pk_set``      ``{p.id}`` (since only ``Pizza p`` was removed from the
    
  383.                 relation)
    
  384. 
    
  385. ``using``       ``"default"`` (since the default router sends writes here)
    
  386. ==============  ============================================================
    
  387. 
    
  388. ``class_prepared``
    
  389. ------------------
    
  390. 
    
  391. .. data:: django.db.models.signals.class_prepared
    
  392.    :module:
    
  393. 
    
  394. Sent whenever a model class has been "prepared" -- that is, once a model has
    
  395. been defined and registered with Django's model system. Django uses this
    
  396. signal internally; it's not generally used in third-party applications.
    
  397. 
    
  398. Since this signal is sent during the app registry population process, and
    
  399. :meth:`AppConfig.ready() <django.apps.AppConfig.ready>` runs after the app
    
  400. registry is fully populated, receivers cannot be connected in that method.
    
  401. One possibility is to connect them ``AppConfig.__init__()`` instead, taking
    
  402. care not to import models or trigger calls to the app registry.
    
  403. 
    
  404. Arguments that are sent with this signal:
    
  405. 
    
  406. ``sender``
    
  407.     The model class which was just prepared.
    
  408. 
    
  409. Management signals
    
  410. ==================
    
  411. 
    
  412. Signals sent by :doc:`django-admin </ref/django-admin>`.
    
  413. 
    
  414. ``pre_migrate``
    
  415. ---------------
    
  416. 
    
  417. .. data:: django.db.models.signals.pre_migrate
    
  418.    :module:
    
  419. 
    
  420. Sent by the :djadmin:`migrate` command before it starts to install an
    
  421. application. It's not emitted for applications that lack a ``models`` module.
    
  422. 
    
  423. Arguments sent with this signal:
    
  424. 
    
  425. ``sender``
    
  426.     An :class:`~django.apps.AppConfig` instance for the application about to
    
  427.     be migrated/synced.
    
  428. 
    
  429. ``app_config``
    
  430.     Same as ``sender``.
    
  431. 
    
  432. ``verbosity``
    
  433.     Indicates how much information ``manage.py`` is printing on screen. See
    
  434.     the :option:`--verbosity` flag for details.
    
  435. 
    
  436.     Functions which listen for :data:`pre_migrate` should adjust what they
    
  437.     output to the screen based on the value of this argument.
    
  438. 
    
  439. ``interactive``
    
  440.     If ``interactive`` is ``True``, it's safe to prompt the user to input
    
  441.     things on the command line. If ``interactive`` is ``False``, functions
    
  442.     which listen for this signal should not try to prompt for anything.
    
  443. 
    
  444.     For example, the :mod:`django.contrib.auth` app only prompts to create a
    
  445.     superuser when ``interactive`` is ``True``.
    
  446. 
    
  447. ``stdout``
    
  448.     .. versionadded:: 4.0
    
  449. 
    
  450.     A stream-like object where verbose output should be redirected.
    
  451. 
    
  452. ``using``
    
  453.     The alias of database on which a command will operate.
    
  454. 
    
  455. ``plan``
    
  456.     The migration plan that is going to be used for the migration run. While
    
  457.     the plan is not public API, this allows for the rare cases when it is
    
  458.     necessary to know the plan. A plan is a list of two-tuples with the first
    
  459.     item being the instance of a migration class and the second item showing
    
  460.     if the migration was rolled back (``True``) or applied (``False``).
    
  461. 
    
  462. ``apps``
    
  463.     An instance of :data:`Apps <django.apps>` containing the state of the
    
  464.     project before the migration run. It should be used instead of the global
    
  465.     :attr:`apps <django.apps.apps>` registry to retrieve the models you
    
  466.     want to perform operations on.
    
  467. 
    
  468. ``post_migrate``
    
  469. ----------------
    
  470. 
    
  471. .. data:: django.db.models.signals.post_migrate
    
  472.    :module:
    
  473. 
    
  474. Sent at the end of the :djadmin:`migrate` (even if no migrations are run) and
    
  475. :djadmin:`flush` commands. It's not emitted for applications that lack a
    
  476. ``models`` module.
    
  477. 
    
  478. Handlers of this signal must not perform database schema alterations as doing
    
  479. so may cause the :djadmin:`flush` command to fail if it runs during the
    
  480. :djadmin:`migrate` command.
    
  481. 
    
  482. Arguments sent with this signal:
    
  483. 
    
  484. ``sender``
    
  485.     An :class:`~django.apps.AppConfig` instance for the application that was
    
  486.     just installed.
    
  487. 
    
  488. ``app_config``
    
  489.     Same as ``sender``.
    
  490. 
    
  491. ``verbosity``
    
  492.     Indicates how much information ``manage.py`` is printing on screen. See
    
  493.     the :option:`--verbosity` flag for details.
    
  494. 
    
  495.     Functions which listen for :data:`post_migrate` should adjust what they
    
  496.     output to the screen based on the value of this argument.
    
  497. 
    
  498. ``interactive``
    
  499.     If ``interactive`` is ``True``, it's safe to prompt the user to input
    
  500.     things on the command line. If ``interactive`` is ``False``, functions
    
  501.     which listen for this signal should not try to prompt for anything.
    
  502. 
    
  503.     For example, the :mod:`django.contrib.auth` app only prompts to create a
    
  504.     superuser when ``interactive`` is ``True``.
    
  505. 
    
  506. ``stdout``
    
  507.     .. versionadded:: 4.0
    
  508. 
    
  509.     A stream-like object where verbose output should be redirected.
    
  510. 
    
  511. ``using``
    
  512.     The database alias used for synchronization. Defaults to the ``default``
    
  513.     database.
    
  514. 
    
  515. ``plan``
    
  516.     The migration plan that was used for the migration run. While the plan is
    
  517.     not public API, this allows for the rare cases when it is necessary to
    
  518.     know the plan. A plan is a list of two-tuples with the first item being
    
  519.     the instance of a migration class and the second item showing if the
    
  520.     migration was rolled back (``True``) or applied (``False``).
    
  521. 
    
  522. ``apps``
    
  523.     An instance of :data:`Apps <django.apps.apps>` containing the state of the
    
  524.     project after the migration run. It should be used instead of the global
    
  525.     :attr:`apps <django.apps.apps>` registry to retrieve the models you
    
  526.     want to perform operations on.
    
  527. 
    
  528. For example, you could register a callback in an
    
  529. :class:`~django.apps.AppConfig` like this::
    
  530. 
    
  531.     from django.apps import AppConfig
    
  532.     from django.db.models.signals import post_migrate
    
  533. 
    
  534.     def my_callback(sender, **kwargs):
    
  535.         # Your specific logic here
    
  536.         pass
    
  537. 
    
  538.     class MyAppConfig(AppConfig):
    
  539.         ...
    
  540. 
    
  541.         def ready(self):
    
  542.             post_migrate.connect(my_callback, sender=self)
    
  543. 
    
  544. .. note::
    
  545. 
    
  546.     If you provide an :class:`~django.apps.AppConfig` instance as the sender
    
  547.     argument, please ensure that the signal is registered in
    
  548.     :meth:`~django.apps.AppConfig.ready`. ``AppConfig``\s are recreated for
    
  549.     tests that run with a modified set of :setting:`INSTALLED_APPS` (such as
    
  550.     when settings are overridden) and such signals should be connected for each
    
  551.     new ``AppConfig`` instance.
    
  552. 
    
  553. Request/response signals
    
  554. ========================
    
  555. 
    
  556. .. module:: django.core.signals
    
  557.    :synopsis: Core signals sent by the request/response system.
    
  558. 
    
  559. Signals sent by the core framework when processing a request.
    
  560. 
    
  561. .. warning::
    
  562. 
    
  563.     Signals can make your code harder to maintain. Consider :doc:`using a
    
  564.     middleware </topics/http/middleware>` before using request/response
    
  565.     signals.
    
  566. 
    
  567. ``request_started``
    
  568. -------------------
    
  569. 
    
  570. .. data:: django.core.signals.request_started
    
  571.    :module:
    
  572. 
    
  573. Sent when Django begins processing an HTTP request.
    
  574. 
    
  575. Arguments sent with this signal:
    
  576. 
    
  577. ``sender``
    
  578.     The handler class -- e.g. ``django.core.handlers.wsgi.WsgiHandler`` -- that
    
  579.     handled the request.
    
  580. ``environ``
    
  581.     The ``environ`` dictionary provided to the request.
    
  582. 
    
  583. ``request_finished``
    
  584. --------------------
    
  585. 
    
  586. .. data:: django.core.signals.request_finished
    
  587.    :module:
    
  588. 
    
  589. Sent when Django finishes delivering an HTTP response to the client.
    
  590. 
    
  591. Arguments sent with this signal:
    
  592. 
    
  593. ``sender``
    
  594.     The handler class, as above.
    
  595. 
    
  596. ``got_request_exception``
    
  597. -------------------------
    
  598. 
    
  599. .. data:: django.core.signals.got_request_exception
    
  600.    :module:
    
  601. 
    
  602. This signal is sent whenever Django encounters an exception while processing an incoming HTTP request.
    
  603. 
    
  604. Arguments sent with this signal:
    
  605. 
    
  606. ``sender``
    
  607.     Unused (always ``None``).
    
  608. 
    
  609. ``request``
    
  610.     The :class:`~django.http.HttpRequest` object.
    
  611. 
    
  612. Test signals
    
  613. ============
    
  614. 
    
  615. .. module:: django.test.signals
    
  616.    :synopsis: Signals sent during testing.
    
  617. 
    
  618. Signals only sent when :ref:`running tests <running-tests>`.
    
  619. 
    
  620. ``setting_changed``
    
  621. -------------------
    
  622. 
    
  623. .. data:: django.test.signals.setting_changed
    
  624.    :module:
    
  625. 
    
  626. This signal is sent when the value of a setting is changed through the
    
  627. ``django.test.TestCase.settings()`` context manager or the
    
  628. :func:`django.test.override_settings` decorator/context manager.
    
  629. 
    
  630. It's actually sent twice: when the new value is applied ("setup") and when the
    
  631. original value is restored ("teardown"). Use the ``enter`` argument to
    
  632. distinguish between the two.
    
  633. 
    
  634. You can also import this signal from ``django.core.signals`` to avoid importing
    
  635. from ``django.test`` in non-test situations.
    
  636. 
    
  637. Arguments sent with this signal:
    
  638. 
    
  639. ``sender``
    
  640.     The settings handler.
    
  641. 
    
  642. ``setting``
    
  643.     The name of the setting.
    
  644. 
    
  645. ``value``
    
  646.     The value of the setting after the change. For settings that initially
    
  647.     don't exist, in the "teardown" phase, ``value`` is ``None``.
    
  648. 
    
  649. ``enter``
    
  650.     A boolean; ``True`` if the setting is applied, ``False`` if restored.
    
  651. 
    
  652. ``template_rendered``
    
  653. ---------------------
    
  654. 
    
  655. .. data:: django.test.signals.template_rendered
    
  656.    :module:
    
  657. 
    
  658. Sent when the test system renders a template. This signal is not emitted during
    
  659. normal operation of a Django server -- it is only available during testing.
    
  660. 
    
  661. Arguments sent with this signal:
    
  662. 
    
  663. ``sender``
    
  664.     The :class:`~django.template.Template` object which was rendered.
    
  665. 
    
  666. ``template``
    
  667.     Same as sender
    
  668. 
    
  669. ``context``
    
  670.     The :class:`~django.template.Context` with which the template was
    
  671.     rendered.
    
  672. 
    
  673. Database Wrappers
    
  674. =================
    
  675. 
    
  676. .. module:: django.db.backends
    
  677.    :synopsis: Core signals sent by the database wrapper.
    
  678. 
    
  679. Signals sent by the database wrapper when a database connection is
    
  680. initiated.
    
  681. 
    
  682. ``connection_created``
    
  683. ----------------------
    
  684. 
    
  685. .. data:: django.db.backends.signals.connection_created
    
  686.    :module:
    
  687. 
    
  688. Sent when the database wrapper makes the initial connection to the
    
  689. database.  This is particularly useful if you'd like to send any post
    
  690. connection commands to the SQL backend.
    
  691. 
    
  692. Arguments sent with this signal:
    
  693. 
    
  694. ``sender``
    
  695.     The database wrapper class -- i.e.
    
  696.     ``django.db.backends.postgresql.DatabaseWrapper`` or
    
  697.     ``django.db.backends.mysql.DatabaseWrapper``, etc.
    
  698. 
    
  699. ``connection``
    
  700.     The database connection that was opened. This can be used in a
    
  701.     multiple-database configuration to differentiate connection signals
    
  702.     from different databases.