{"title":"Signals","version":"2.2","locale":"en","docname":"ref/signals","url":"/en/2.2/ref/signals/","canonical":"https://djangodocs.dev/en/2.2/ref/signals/","summary":"A list of all the signals that Django sends. All built-in signals are sent using the send() method. See also See the documentation on the signal dispatcher for…","html":"<h1>Signals<a class=\"heading-anchor\" href=\"#signals\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>A list of all the signals that Django sends. All built-in signals are sent\nusing the <a class=\"reference internal\" href=\"/en/2.2/topics/signals/#django.dispatch.Signal.send\" title=\"django.dispatch.Signal.send\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">send()</span></code></a> method.</p>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<p>See the documentation on the <a class=\"reference internal\" href=\"/en/2.2/topics/signals/\"><span class=\"doc\">signal dispatcher</span></a> for\ninformation regarding how to register for and receive signals.</p>\n<p>The <a class=\"reference internal\" href=\"/en/2.2/topics/auth/\"><span class=\"doc\">authentication framework</span></a> sends <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/auth/#topics-auth-signals\"><span class=\"std std-ref\">signals when\na user is logged in / out</span></a>.</p>\n</aside>\n<section id=\"module-django.db.models.signals\">\n<span id=\"model-signals\"></span><h2>Model signals<a class=\"heading-anchor\" href=\"#module-django.db.models.signals\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <a class=\"reference internal\" href=\"#module-django.db.models.signals\" title=\"django.db.models.signals: Signals sent by the model system.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.db.models.signals</span></code></a> module defines a set of signals sent by the\nmodel system.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>Many of these signals are sent by various model methods like\n<code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code> or <a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">save()</span></code></a> that you can\noverride in your own code.</p>\n<p>If you override these methods on your model, you must call the parent class’\nmethods for these signals to be sent.</p>\n<p>Note also that Django stores signal handlers as weak references by default,\nso if your handler is a local function, it may be garbage collected.  To\nprevent this, pass <code class=\"docutils literal notranslate\"><span class=\"pre\">weak=False</span></code> when you call the signal’s <a class=\"reference internal\" href=\"/en/2.2/topics/signals/#django.dispatch.Signal.connect\" title=\"django.dispatch.Signal.connect\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">connect()</span></code></a>.</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Model signals <code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code> model can be lazily referenced when connecting a\nreceiver by specifying its full application label. For example, an\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Question</span></code> model defined in the <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code> application could be referenced\nas <code class=\"docutils literal notranslate\"><span class=\"pre\">'polls.Question'</span></code>. This sort of reference can be quite handy when\ndealing with circular import dependencies and swappable models.</p>\n</aside>\n<section id=\"pre-init\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">pre_init</span></code><a class=\"heading-anchor\" href=\"#pre-init\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.pre_init\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">pre_init</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_init\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Whenever you instantiate a Django model, this signal is sent at the beginning\nof the model’s <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The model class that just had an instance created.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">args</span></code></dt><dd><p>A list of positional arguments passed to <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">kwargs</span></code></dt><dd><p>A dictionary of keyword arguments passed to <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code>.</p>\n</dd>\n</dl>\n<p>For example, the <a class=\"reference internal\" href=\"/en/2.2/intro/tutorial02/\"><span class=\"doc\">tutorial</span></a> has this line:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">q</span> <span class=\"o\">=</span> <span class=\"n\">Question</span><span class=\"p\">(</span><span class=\"n\">question_text</span><span class=\"o\">=</span><span class=\"s2\">&quot;What&#39;s new?&quot;</span><span class=\"p\">,</span> <span class=\"n\">pub_date</span><span class=\"o\">=</span><span class=\"n\">timezone</span><span class=\"o\">.</span><span class=\"n\">now</span><span class=\"p\">())</span>\n</code></pre></div>\n<p>The arguments sent to a <a class=\"reference internal\" href=\"#django.db.models.signals.pre_init\" title=\"django.db.models.signals.pre_init\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_init</span></code></a> handler would be:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Argument</p></th>\n<th class=\"head\"><p>Value</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">Question</span></code> (the class itself)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">args</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">[]</span></code> (an empty list because there were no positional\narguments passed to <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code>)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">kwargs</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">{'question_text':</span> <span class=\"pre\">&quot;What's</span> <span class=\"pre\">new?&quot;,</span></code>\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'pub_date':</span> <span class=\"pre\">datetime.datetime(2012,</span> <span class=\"pre\">2,</span> <span class=\"pre\">26,</span> <span class=\"pre\">13,</span> <span class=\"pre\">0,</span> <span class=\"pre\">0,</span> <span class=\"pre\">775217,</span> <span class=\"pre\">tzinfo=&lt;UTC&gt;)}</span></code></p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"post-init\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">post_init</span></code><a class=\"heading-anchor\" href=\"#post-init\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.post_init\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">post_init</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_init\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Like pre_init, but this one is sent when the <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code> method finishes.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>As above: the model class that just had an instance created.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></dt><dd><p>The actual instance of the model that’s just been created.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">instance._state</span></code> isn’t set before sending the <code class=\"docutils literal notranslate\"><span class=\"pre\">post_init</span></code> signal,\nso <code class=\"docutils literal notranslate\"><span class=\"pre\">_state</span></code> attributes always have their default values. For example,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">_state.db</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> and cannot be used to check an <code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code>\ndatabase.</p>\n</aside>\n</dd>\n</dl>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p>For performance reasons, you shouldn’t perform queries in receivers of\n<code class=\"docutils literal notranslate\"><span class=\"pre\">pre_init</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">post_init</span></code> signals because they would be executed for\neach instance returned during queryset iteration.</p>\n</aside>\n</section>\n<section id=\"pre-save\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">pre_save</span></code><a class=\"heading-anchor\" href=\"#pre-save\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.pre_save\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">pre_save</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_save\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>This is sent at the beginning of a model’s <a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">save()</span></code></a>\nmethod.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></dt><dd><p>The actual instance being saved.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">raw</span></code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> if the model is saved exactly as presented\n(i.e. when loading a fixture). One should not query/modify other\nrecords in the database as the database might not be in a\nconsistent state yet.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The database alias being used.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">update_fields</span></code></dt><dd><p>The set of fields to update as passed to <a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">Model.save()</span></code></a>, or <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>\nif <code class=\"docutils literal notranslate\"><span class=\"pre\">update_fields</span></code> wasn’t passed to <code class=\"docutils literal notranslate\"><span class=\"pre\">save()</span></code>.</p>\n</dd>\n</dl>\n</section>\n<section id=\"post-save\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">post_save</span></code><a class=\"heading-anchor\" href=\"#post-save\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.post_save\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">post_save</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_save\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Like <a class=\"reference internal\" href=\"#django.db.models.signals.pre_save\" title=\"django.db.models.signals.pre_save\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_save</span></code></a>, but sent at the end of the\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">save()</span></code></a> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></dt><dd><p>The actual instance being saved.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">created</span></code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> if a new record was created.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">raw</span></code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> if the model is saved exactly as presented\n(i.e. when loading a fixture). One should not query/modify other\nrecords in the database as the database might not be in a\nconsistent state yet.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The database alias being used.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">update_fields</span></code></dt><dd><p>The set of fields to update as passed to <a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">Model.save()</span></code></a>, or <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>\nif <code class=\"docutils literal notranslate\"><span class=\"pre\">update_fields</span></code> wasn’t passed to <code class=\"docutils literal notranslate\"><span class=\"pre\">save()</span></code>.</p>\n</dd>\n</dl>\n</section>\n<section id=\"pre-delete\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">pre_delete</span></code><a class=\"heading-anchor\" href=\"#pre-delete\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.pre_delete\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">pre_delete</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_delete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent at the beginning of a model’s <a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">delete()</span></code></a>\nmethod and a queryset’s <a class=\"reference internal\" href=\"/en/2.2/ref/models/querysets/#django.db.models.query.QuerySet.delete\" title=\"django.db.models.query.QuerySet.delete\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">delete()</span></code></a> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></dt><dd><p>The actual instance being deleted.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The database alias being used.</p>\n</dd>\n</dl>\n</section>\n<section id=\"post-delete\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">post_delete</span></code><a class=\"heading-anchor\" href=\"#post-delete\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.post_delete\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">post_delete</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_delete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Like <a class=\"reference internal\" href=\"#django.db.models.signals.pre_delete\" title=\"django.db.models.signals.pre_delete\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_delete</span></code></a>, but sent at the end of a model’s\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">delete()</span></code></a> method and a queryset’s\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/querysets/#django.db.models.query.QuerySet.delete\" title=\"django.db.models.query.QuerySet.delete\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">delete()</span></code></a> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></dt><dd><p>The actual instance being deleted.</p>\n<p>Note that the object will no longer be in the database, so be very\ncareful what you do with this instance.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The database alias being used.</p>\n</dd>\n</dl>\n</section>\n<section id=\"m2m-changed\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">m2m_changed</span></code><a class=\"heading-anchor\" href=\"#m2m-changed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.m2m_changed\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">m2m_changed</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.m2m_changed\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent when a <a class=\"reference internal\" href=\"/en/2.2/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code></a> is changed on a model\ninstance. Strictly speaking, this is not a model signal since it is sent by the\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code></a>, but since it complements the\n<a class=\"reference internal\" href=\"#django.db.models.signals.pre_save\" title=\"django.db.models.signals.pre_save\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_save</span></code></a>/<a class=\"reference internal\" href=\"#django.db.models.signals.post_save\" title=\"django.db.models.signals.post_save\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">post_save</span></code></a> and <a class=\"reference internal\" href=\"#django.db.models.signals.pre_delete\" title=\"django.db.models.signals.pre_delete\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_delete</span></code></a>/<a class=\"reference internal\" href=\"#django.db.models.signals.post_delete\" title=\"django.db.models.signals.post_delete\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">post_delete</span></code></a>\nwhen it comes to tracking changes to models, it is included here.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The intermediate model class describing the\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code></a>. This class is automatically\ncreated when a many-to-many field is defined; you can access it using the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">through</span></code> attribute on the many-to-many field.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></dt><dd><p>The instance whose many-to-many relation is updated. This can be an\ninstance of the <code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code>, or of the class the\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code></a> is related to.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">action</span></code></dt><dd><p>A string indicating the type of update that is done on the relation.\nThis can be one of the following:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pre_add&quot;</span></code></dt><dd><p>Sent <em>before</em> one or more objects are added to the relation.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;post_add&quot;</span></code></dt><dd><p>Sent <em>after</em> one or more objects are added to the relation.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pre_remove&quot;</span></code></dt><dd><p>Sent <em>before</em> one or more objects are removed from the relation.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;post_remove&quot;</span></code></dt><dd><p>Sent <em>after</em> one or more objects are removed from the relation.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pre_clear&quot;</span></code></dt><dd><p>Sent <em>before</em> the relation is cleared.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;post_clear&quot;</span></code></dt><dd><p>Sent <em>after</em> the relation is cleared.</p>\n</dd>\n</dl>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">reverse</span></code></dt><dd><p>Indicates which side of the relation is updated (i.e., if it is the\nforward or reverse relation that is being modified).</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">model</span></code></dt><dd><p>The class of the objects that are added to, removed from or cleared\nfrom the relation.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">pk_set</span></code></dt><dd><p>For the <code class=\"docutils literal notranslate\"><span class=\"pre\">pre_add</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">post_add</span></code> actions, this is a set of primary key\nvalues that will be, or have been, added to the relation. This may be a\nsubset of the values submitted to be added, since inserts must filter\nexisting values in order to avoid a database <code class=\"docutils literal notranslate\"><span class=\"pre\">IntegrityError</span></code>.</p>\n<p>For the <code class=\"docutils literal notranslate\"><span class=\"pre\">pre_remove</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">post_remove</span></code> actions, this is a set of\nprimary key values that was submitted to be removed from the relation. This\nis not dependent on whether the values actually will be, or have been,\nremoved. In particular, non-existent values may be submitted, and will\nappear in <code class=\"docutils literal notranslate\"><span class=\"pre\">pk_set</span></code>, even though they have no effect on the database.</p>\n<p>For the <code class=\"docutils literal notranslate\"><span class=\"pre\">pre_clear</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">post_clear</span></code> actions, this is <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The database alias being used.</p>\n</dd>\n</dl>\n<p>For example, if a <code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span></code> can have multiple <code class=\"docutils literal notranslate\"><span class=\"pre\">Topping</span></code> objects, modeled\nlike this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Topping</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"k\">pass</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Pizza</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"n\">toppings</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">ManyToManyField</span><span class=\"p\">(</span><span class=\"n\">Topping</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>If we connected a handler like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db.models.signals</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">m2m_changed</span>\n\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">toppings_changed</span><span class=\"p\">(</span><span class=\"n\">sender</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">kwargs</span><span class=\"p\">):</span>\n    <span class=\"c1\"># Do something</span>\n    <span class=\"k\">pass</span>\n\n<span class=\"n\">m2m_changed</span><span class=\"o\">.</span><span class=\"n\">connect</span><span class=\"p\">(</span><span class=\"n\">toppings_changed</span><span class=\"p\">,</span> <span class=\"n\">sender</span><span class=\"o\">=</span><span class=\"n\">Pizza</span><span class=\"o\">.</span><span class=\"n\">toppings</span><span class=\"o\">.</span><span class=\"n\">through</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>and then did something like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">p</span> <span class=\"o\">=</span> <span class=\"n\">Pizza</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">create</span><span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">t</span> <span class=\"o\">=</span> <span class=\"n\">Topping</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">create</span><span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">p</span><span class=\"o\">.</span><span class=\"n\">toppings</span><span class=\"o\">.</span><span class=\"n\">add</span><span class=\"p\">(</span><span class=\"n\">t</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>the arguments sent to a <a class=\"reference internal\" href=\"#django.db.models.signals.m2m_changed\" title=\"django.db.models.signals.m2m_changed\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">m2m_changed</span></code></a> handler (<code class=\"docutils literal notranslate\"><span class=\"pre\">toppings_changed</span></code> in\nthe example above) would be:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Argument</p></th>\n<th class=\"head\"><p>Value</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza.toppings.through</span></code> (the intermediate m2m class)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">p</span></code> (the <code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span></code> instance being modified)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">action</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pre_add&quot;</span></code> (followed by a separate signal with <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;post_add&quot;</span></code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">reverse</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> (<code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span></code> contains the\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code></a>, so this call\nmodifies the forward relation)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">model</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">Topping</span></code> (the class of the objects added to the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span></code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">pk_set</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">{t.id}</span></code> (since only <code class=\"docutils literal notranslate\"><span class=\"pre\">Topping</span> <span class=\"pre\">t</span></code> was added to the relation)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;default&quot;</span></code> (since the default router sends writes here)</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>And if we would then do something like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">t</span><span class=\"o\">.</span><span class=\"n\">pizza_set</span><span class=\"o\">.</span><span class=\"n\">remove</span><span class=\"p\">(</span><span class=\"n\">p</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>the arguments sent to a <a class=\"reference internal\" href=\"#django.db.models.signals.m2m_changed\" title=\"django.db.models.signals.m2m_changed\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">m2m_changed</span></code></a> handler would be:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Argument</p></th>\n<th class=\"head\"><p>Value</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza.toppings.through</span></code> (the intermediate m2m class)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">instance</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">t</span></code> (the <code class=\"docutils literal notranslate\"><span class=\"pre\">Topping</span></code> instance being modified)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">action</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;pre_remove&quot;</span></code> (followed by a separate signal with <code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;post_remove&quot;</span></code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">reverse</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> (<code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span></code> contains the\n<a class=\"reference internal\" href=\"/en/2.2/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ManyToManyField</span></code></a>, so this call\nmodifies the reverse relation)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">model</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span></code> (the class of the objects removed from the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Topping</span></code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">pk_set</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">{p.id}</span></code> (since only <code class=\"docutils literal notranslate\"><span class=\"pre\">Pizza</span> <span class=\"pre\">p</span></code> was removed from the\nrelation)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">&quot;default&quot;</span></code> (since the default router sends writes here)</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"class-prepared\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">class_prepared</span></code><a class=\"heading-anchor\" href=\"#class-prepared\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.class_prepared\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">class_prepared</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.class_prepared\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent whenever a model class has been “prepared” – that is, once model has\nbeen defined and registered with Django’s model system. Django uses this\nsignal internally; it’s not generally used in third-party applications.</p>\n<p>Since this signal is sent during the app registry population process, and\n<a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">AppConfig.ready()</span></code></a> runs after the app\nregistry is fully populated, receivers cannot be connected in that method.\nOne possibility is to connect them <code class=\"docutils literal notranslate\"><span class=\"pre\">AppConfig.__init__()</span></code> instead, taking\ncare not to import models or trigger calls to the app registry.</p>\n<p>Arguments that are sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The model class which was just prepared.</p>\n</dd>\n</dl>\n</section>\n</section>\n<section id=\"management-signals\">\n<h2>Management signals<a class=\"heading-anchor\" href=\"#management-signals\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Signals sent by <a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/\"><span class=\"doc\">django-admin</span></a>.</p>\n<section id=\"pre-migrate\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">pre_migrate</span></code><a class=\"heading-anchor\" href=\"#pre-migrate\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.pre_migrate\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">pre_migrate</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_migrate\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent by the <a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">migrate</span></code></a> command before it starts to install an\napplication. It’s not emitted for applications that lack a <code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code> module.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>An <a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> instance for the application about to\nbe migrated/synced.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">app_config</span></code></dt><dd><p>Same as <code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">verbosity</span></code></dt><dd><p>Indicates how much information manage.py is printing on screen. See\nthe <a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#cmdoption-verbosity\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">--verbosity</span></code></a> flag for details.</p>\n<p>Functions which listen for <a class=\"reference internal\" href=\"#django.db.models.signals.pre_migrate\" title=\"django.db.models.signals.pre_migrate\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_migrate</span></code></a> should adjust what they\noutput to the screen based on the value of this argument.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code></dt><dd><p>If <code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, it’s safe to prompt the user to input\nthings on the command line. If <code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>, functions\nwhich listen for this signal should not try to prompt for anything.</p>\n<p>For example, the <a class=\"reference internal\" href=\"/en/2.2/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code></a> app only prompts to create a\nsuperuser when <code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The alias of database on which a command will operate.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">plan</span></code></dt><dd><p>The migration plan that is going to be used for the migration run. While\nthe plan is not public API, this allows for the rare cases when it is\nnecessary to know the plan. A plan is a list of two-tuples with the first\nitem being the instance of a migration class and the second item showing\nif the migration was rolled back (<code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>) or applied (<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>).</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">apps</span></code></dt><dd><p>An instance of <a class=\"reference internal\" href=\"/en/2.2/ref/applications/#module-django.apps\" title=\"django.apps\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">Apps</span></code></a> containing the state of the\nproject before the migration run. It should be used instead of the global\n<a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">apps</span></code></a> registry to retrieve the models you\nwant to perform operations on.</p>\n</dd>\n</dl>\n</section>\n<section id=\"post-migrate\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">post_migrate</span></code><a class=\"heading-anchor\" href=\"#post-migrate\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.models.signals.post_migrate\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.models.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">post_migrate</span></span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_migrate\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent at the end of the <a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">migrate</span></code></a> (even if no migrations are run) and\n<a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#django-admin-flush\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">flush</span></code></a> commands. It’s not emitted for applications that lack a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code> module.</p>\n<p>Handlers of this signal must not perform database schema alterations as doing\nso may cause the <a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#django-admin-flush\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">flush</span></code></a> command to fail if it runs during the\n<a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">migrate</span></code></a> command.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>An <a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> instance for the application that was\njust installed.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">app_config</span></code></dt><dd><p>Same as <code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">verbosity</span></code></dt><dd><p>Indicates how much information manage.py is printing on screen. See\nthe <a class=\"reference internal\" href=\"/en/2.2/ref/django-admin/#cmdoption-verbosity\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">--verbosity</span></code></a> flag for details.</p>\n<p>Functions which listen for <a class=\"reference internal\" href=\"#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">post_migrate</span></code></a> should adjust what they\noutput to the screen based on the value of this argument.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code></dt><dd><p>If <code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, it’s safe to prompt the user to input\nthings on the command line. If <code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>, functions\nwhich listen for this signal should not try to prompt for anything.</p>\n<p>For example, the <a class=\"reference internal\" href=\"/en/2.2/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code></a> app only prompts to create a\nsuperuser when <code class=\"docutils literal notranslate\"><span class=\"pre\">interactive</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">using</span></code></dt><dd><p>The database alias used for synchronization. Defaults to the <code class=\"docutils literal notranslate\"><span class=\"pre\">default</span></code>\ndatabase.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">plan</span></code></dt><dd><p>The migration plan that was used for the migration run. While the plan is\nnot public API, this allows for the rare cases when it is necessary to\nknow the plan. A plan is a list of two-tuples with the first item being\nthe instance of a migration class and the second item showing if the\nmigration was rolled back (<code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>) or applied (<code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>).</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">apps</span></code></dt><dd><p>An instance of <a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">Apps</span></code></a> containing the state of the\nproject after the migration run. It should be used instead of the global\n<a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">apps</span></code></a> registry to retrieve the models you\nwant to perform operations on.</p>\n</dd>\n</dl>\n<p>For example, you could register a callback in an\n<a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">AppConfig</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db.models.signals</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">post_migrate</span>\n\n<span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">my_callback</span><span class=\"p\">(</span><span class=\"n\">sender</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">kwargs</span><span class=\"p\">):</span>\n    <span class=\"c1\"># Your specific logic here</span>\n    <span class=\"k\">pass</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">MyAppConfig</span><span class=\"p\">(</span><span class=\"n\">AppConfig</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">ready</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"n\">post_migrate</span><span class=\"o\">.</span><span class=\"n\">connect</span><span class=\"p\">(</span><span class=\"n\">my_callback</span><span class=\"p\">,</span> <span class=\"n\">sender</span><span class=\"o\">=</span><span class=\"bp\">self</span><span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>If you provide an <a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> instance as the sender\nargument, please ensure that the signal is registered in\n<a class=\"reference internal\" href=\"/en/2.2/ref/applications/#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">ready()</span></code></a>. <code class=\"docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code>s are recreated for\ntests that run with a modified set of <a class=\"reference internal\" href=\"/en/2.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> (such as\nwhen settings are overridden) and such signals should be connected for each\nnew <code class=\"docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code> instance.</p>\n</aside>\n</section>\n</section>\n<section id=\"module-django.core.signals\">\n<span id=\"request-response-signals\"></span><h2>Request/response signals<a class=\"heading-anchor\" href=\"#module-django.core.signals\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Signals sent by the core framework when processing a request.</p>\n<section id=\"request-started\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">request_started</span></code><a class=\"heading-anchor\" href=\"#request-started\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.core.signals.request_started\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.core.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">request_started</span></span><a class=\"heading-anchor\" href=\"#django.core.signals.request_started\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent when Django begins processing an HTTP request.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The handler class – e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">django.core.handlers.wsgi.WsgiHandler</span></code> – that\nhandled the request.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">environ</span></code></dt><dd><p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">environ</span></code> dictionary provided to the request.</p>\n</dd>\n</dl>\n</section>\n<section id=\"request-finished\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">request_finished</span></code><a class=\"heading-anchor\" href=\"#request-finished\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.core.signals.request_finished\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.core.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">request_finished</span></span><a class=\"heading-anchor\" href=\"#django.core.signals.request_finished\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent when Django finishes delivering an HTTP response to the client.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The handler class, as above.</p>\n</dd>\n</dl>\n</section>\n<section id=\"got-request-exception\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">got_request_exception</span></code><a class=\"heading-anchor\" href=\"#got-request-exception\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.core.signals.got_request_exception\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.core.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">got_request_exception</span></span><a class=\"heading-anchor\" href=\"#django.core.signals.got_request_exception\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>This signal is sent whenever Django encounters an exception while processing an incoming HTTP request.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>Unused (always <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>).</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">request</span></code></dt><dd><p>The <a class=\"reference internal\" href=\"/en/2.2/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code></a> object.</p>\n</dd>\n</dl>\n</section>\n</section>\n<section id=\"module-django.test.signals\">\n<span id=\"test-signals\"></span><h2>Test signals<a class=\"heading-anchor\" href=\"#module-django.test.signals\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Signals only sent when <a class=\"reference internal\" href=\"/en/2.2/topics/testing/overview/#running-tests\"><span class=\"std std-ref\">running tests</span></a>.</p>\n<section id=\"setting-changed\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">setting_changed</span></code><a class=\"heading-anchor\" href=\"#setting-changed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.test.signals.setting_changed\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.test.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">setting_changed</span></span><a class=\"heading-anchor\" href=\"#django.test.signals.setting_changed\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>This signal is sent when the value of a setting is changed through the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.test.TestCase.settings()</span></code> context manager or the\n<a class=\"reference internal\" href=\"/en/2.2/topics/testing/tools/#django.test.override_settings\" title=\"django.test.override_settings\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.test.override_settings()</span></code></a> decorator/context manager.</p>\n<p>It’s actually sent twice: when the new value is applied (“setup”) and when the\noriginal value is restored (“teardown”). Use the <code class=\"docutils literal notranslate\"><span class=\"pre\">enter</span></code> argument to\ndistinguish between the two.</p>\n<p>You can also import this signal from <code class=\"docutils literal notranslate\"><span class=\"pre\">django.core.signals</span></code> to avoid importing\nfrom <code class=\"docutils literal notranslate\"><span class=\"pre\">django.test</span></code> in non-test situations.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The settings handler.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">setting</span></code></dt><dd><p>The name of the setting.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">value</span></code></dt><dd><p>The value of the setting after the change. For settings that initially\ndon’t exist, in the “teardown” phase, <code class=\"docutils literal notranslate\"><span class=\"pre\">value</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">enter</span></code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> if the setting is applied, <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> if restored.</p>\n</dd>\n</dl>\n</section>\n<section id=\"template-rendered\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">template_rendered</span></code><a class=\"heading-anchor\" href=\"#template-rendered\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.test.signals.template_rendered\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.test.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">template_rendered</span></span><a class=\"heading-anchor\" href=\"#django.test.signals.template_rendered\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent when the test system renders a template. This signal is not emitted during\nnormal operation of a Django server – it is only available during testing.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The <a class=\"reference internal\" href=\"/en/2.2/ref/templates/api/#django.template.Template\" title=\"django.template.Template\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Template</span></code></a> object which was rendered.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">template</span></code></dt><dd><p>Same as sender</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">context</span></code></dt><dd><p>The <a class=\"reference internal\" href=\"/en/2.2/ref/templates/api/#django.template.Context\" title=\"django.template.Context\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Context</span></code></a> with which the template was\nrendered.</p>\n</dd>\n</dl>\n</section>\n</section>\n<section id=\"module-django.db.backends\">\n<span id=\"database-wrappers\"></span><h2>Database Wrappers<a class=\"heading-anchor\" href=\"#module-django.db.backends\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Signals sent by the database wrapper when a database connection is\ninitiated.</p>\n<section id=\"connection-created\">\n<h3><code class=\"docutils literal notranslate\"><span class=\"pre\">connection_created</span></code><a class=\"heading-anchor\" href=\"#connection-created\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.db.backends.signals.connection_created\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.db.backends.signals.</span></span><span class=\"sig-name descname\"><span class=\"pre\">connection_created</span></span><a class=\"heading-anchor\" href=\"#django.db.backends.signals.connection_created\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent when the database wrapper makes the initial connection to the\ndatabase.  This is particularly useful if you’d like to send any post\nconnection commands to the SQL backend.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">sender</span></code></dt><dd><p>The database wrapper class – i.e.\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.backends.postgresql.DatabaseWrapper</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.backends.mysql.DatabaseWrapper</span></code>, etc.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\"><span class=\"pre\">connection</span></code></dt><dd><p>The database connection that was opened. This can be used in a\nmultiple-database configuration to differentiate connection signals\nfrom different databases.</p>\n</dd>\n</dl>\n</section>\n</section>","rootId":"signals","toc":[{"title":"Model signals","anchor":"module-django.db.models.signals","children":[{"title":"pre_init","anchor":"pre-init","children":[]},{"title":"post_init","anchor":"post-init","children":[]},{"title":"pre_save","anchor":"pre-save","children":[]},{"title":"post_save","anchor":"post-save","children":[]},{"title":"pre_delete","anchor":"pre-delete","children":[]},{"title":"post_delete","anchor":"post-delete","children":[]},{"title":"m2m_changed","anchor":"m2m-changed","children":[]},{"title":"class_prepared","anchor":"class-prepared","children":[]}]},{"title":"Management signals","anchor":"management-signals","children":[{"title":"pre_migrate","anchor":"pre-migrate","children":[]},{"title":"post_migrate","anchor":"post-migrate","children":[]}]},{"title":"Request/response signals","anchor":"module-django.core.signals","children":[{"title":"request_started","anchor":"request-started","children":[]},{"title":"request_finished","anchor":"request-finished","children":[]},{"title":"got_request_exception","anchor":"got-request-exception","children":[]}]},{"title":"Test signals","anchor":"module-django.test.signals","children":[{"title":"setting_changed","anchor":"setting-changed","children":[]},{"title":"template_rendered","anchor":"template-rendered","children":[]}]},{"title":"Database Wrappers","anchor":"module-django.db.backends","children":[{"title":"connection_created","anchor":"connection-created","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/en/2.2/ref/"}],"prev":{"docname":"ref/settings","title":"Settings","url":"/en/2.2/ref/settings/"},"next":{"docname":"ref/templates/index","title":"Templates","url":"/en/2.2/ref/templates/"},"formats":{"html":"/en/2.2/ref/signals/","markdown":"/en/2.2/ref/signals.md","json":"/en/2.2/ref/signals.json"},"source":"https://github.com/django/django/blob/stable/2.2.x/docs/ref/signals.txt","official":"https://docs.djangoproject.com/en/2.2/ref/signals/","inVersions":["dev","6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9","1.8"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}