{"title":"Signals","version":"1.10","locale":"pt-br","docname":"ref/signals","url":"/pt-br/1.10/ref/signals/","canonical":"https://djangodocs.dev/pt-br/1.10/ref/signals/","summary":"A list of all the signals that Django sends. All built-in signals are sent using the send() method.","html":"<h1>Signals<a class=\"heading-anchor\" href=\"#signals\"><span class=\"visually-hidden\">Link para este cabeçalho</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=\"/pt-br/1.10/topics/signals/#django.dispatch.Signal.send\" title=\"django.dispatch.Signal.send\"><code class=\"xref py py-meth docutils literal notranslate\">send()</code></a> method.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Ver também</p>\n<p>See the documentation on the <a class=\"reference internal\" href=\"/pt-br/1.10/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=\"/pt-br/1.10/topics/auth/\"><span class=\"doc\">authentication framework</span></a> sends <a class=\"reference internal\" href=\"/pt-br/1.10/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 para este cabeçalho</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\">django.db.models.signals</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\">Aviso</p>\n<p>Many of these signals are sent by various model methods like\n<code class=\"docutils literal notranslate\">__init__()</code> or <a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">save()</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 this 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\">weak=False</code> when you call the signal’s <a class=\"reference internal\" href=\"/pt-br/1.10/topics/signals/#django.dispatch.Signal.connect\" title=\"django.dispatch.Signal.connect\"><code class=\"xref py py-meth docutils literal notranslate\">connect()</code></a>.</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>Model signals <code class=\"docutils literal notranslate\">sender</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\">Answer</code> model defined in the <code class=\"docutils literal notranslate\">polls</code> application could be referenced\nas <code class=\"docutils literal notranslate\">'polls.Answer'</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\">pre_init</code><a class=\"heading-anchor\" href=\"#pre-init\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">pre_init</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_init\"><span class=\"visually-hidden\">Link para esta definição</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\">__init__()</code> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>The model class that just had an instance created.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">args</code></dt><dd><p>A list of positional arguments passed to <code class=\"docutils literal notranslate\">__init__()</code>:</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">kwargs</code></dt><dd><p>A dictionary of keyword arguments passed to <code class=\"docutils literal notranslate\">__init__()</code>:</p>\n</dd>\n</dl>\n<p>For example, the <a class=\"reference internal\" href=\"/pt-br/1.10/intro/tutorial01/\"><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>p <span class=\"o\">=</span> Poll<span class=\"p\">(</span>question<span class=\"o\">=</span><span class=\"s2\">&quot;What&#39;s up?&quot;</span><span class=\"p\">,</span> pub_date<span class=\"o\">=</span>datetime<span class=\"o\">.</span>now<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\">pre_init</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\">sender</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">Poll</code> (the class itself)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">args</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">[]</code> (an empty list because there were no positional\narguments passed to <code class=\"docutils literal notranslate\">__init__()</code>.)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\">kwargs</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">{'question': &quot;What's up?&quot;, 'pub_date': datetime.now()}</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\">post_init</code><a class=\"heading-anchor\" href=\"#post-init\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">post_init</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_init\"><span class=\"visually-hidden\">Link para esta definição</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\">__init__()</code> method finishes.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\">sender</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\">instance</code></dt><dd><p>The actual instance of the model that’s just been created.</p>\n</dd>\n</dl>\n</section>\n<section id=\"pre-save\">\n<h3><code class=\"docutils literal notranslate\">pre_save</code><a class=\"heading-anchor\" href=\"#pre-save\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">pre_save</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_save\"><span class=\"visually-hidden\">Link para esta definição</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=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">save()</code></a>\nmethod.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">instance</code></dt><dd><p>The actual instance being saved.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">raw</code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\">True</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\">using</code></dt><dd><p>The database alias being used.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">update_fields</code></dt><dd><p>The set of fields to update as passed to <a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">Model.save()</code></a>, or <code class=\"docutils literal notranslate\">None</code>\nif <code class=\"docutils literal notranslate\">update_fields</code> wasn’t passed to <code class=\"docutils literal notranslate\">save()</code>.</p>\n</dd>\n</dl>\n</section>\n<section id=\"post-save\">\n<h3><code class=\"docutils literal notranslate\">post_save</code><a class=\"heading-anchor\" href=\"#post-save\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">post_save</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_save\"><span class=\"visually-hidden\">Link para esta definição</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\">pre_save</code></a>, but sent at the end of the\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">save()</code></a> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">instance</code></dt><dd><p>The actual instance being saved.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">created</code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\">True</code> if a new record was created.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">raw</code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\">True</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\">using</code></dt><dd><p>The database alias being used.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">update_fields</code></dt><dd><p>The set of fields to update as passed to <a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\">Model.save()</code></a>, or <code class=\"docutils literal notranslate\">None</code>\nif <code class=\"docutils literal notranslate\">update_fields</code> wasn’t passed to <code class=\"docutils literal notranslate\">save()</code>.</p>\n</dd>\n</dl>\n</section>\n<section id=\"pre-delete\">\n<h3><code class=\"docutils literal notranslate\">pre_delete</code><a class=\"heading-anchor\" href=\"#pre-delete\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">pre_delete</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_delete\"><span class=\"visually-hidden\">Link para esta definição</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=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\">delete()</code></a>\nmethod and a queryset’s <a class=\"reference internal\" href=\"/pt-br/1.10/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\">delete()</code></a> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">instance</code></dt><dd><p>The actual instance being deleted.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">using</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\">post_delete</code><a class=\"heading-anchor\" href=\"#post-delete\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">post_delete</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_delete\"><span class=\"visually-hidden\">Link para esta definição</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\">pre_delete</code></a>, but sent at the end of a model’s\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\">delete()</code></a> method and a queryset’s\n<a class=\"reference internal\" href=\"/pt-br/1.10/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\">delete()</code></a> method.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>The model class.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">instance</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\">using</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\">m2m_changed</code><a class=\"heading-anchor\" href=\"#m2m-changed\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">m2m_changed</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.m2m_changed\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent when a <a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</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=\"/pt-br/1.10/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</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\">pre_save</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\">post_save</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\">pre_delete</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\">post_delete</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\">sender</code></dt><dd><p>The intermediate model class describing the\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</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\">through</code> attribute on the many-to-many field.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">instance</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\">sender</code>, or of the class the\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</code></a> is related to.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">action</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\">&quot;pre_add&quot;</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\">&quot;post_add&quot;</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\">&quot;pre_remove&quot;</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\">&quot;post_remove&quot;</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\">&quot;pre_clear&quot;</code></dt><dd><p>Sent <em>before</em> the relation is cleared.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">&quot;post_clear&quot;</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\">reverse</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\">model</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\">pk_set</code></dt><dd><p>For the <code class=\"docutils literal notranslate\">pre_add</code>, <code class=\"docutils literal notranslate\">post_add</code>, <code class=\"docutils literal notranslate\">pre_remove</code> and <code class=\"docutils literal notranslate\">post_remove</code>\nactions, this is a set of primary key values that have been added to\nor removed from the relation.</p>\n<p>For the <code class=\"docutils literal notranslate\">pre_clear</code> and <code class=\"docutils literal notranslate\">post_clear</code> actions, this is <code class=\"docutils literal notranslate\">None</code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">using</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\">Pizza</code> can have multiple <code class=\"docutils literal notranslate\">Topping</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=\"nc\">Topping</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"k\">pass</span>\n\n<span class=\"k\">class</span> <span class=\"nc\">Pizza</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n    toppings <span class=\"o\">=</span> models<span class=\"o\">.</span>ManyToManyField<span class=\"p\">(</span>Topping<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=\"nn\">django.db.models.signals</span> <span class=\"kn\">import</span> m2m_changed\n\n<span class=\"k\">def</span> <span class=\"nf\">toppings_changed</span><span class=\"p\">(</span>sender<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n    <span class=\"c1\"># Do something</span>\n    <span class=\"k\">pass</span>\n\nm2m_changed<span class=\"o\">.</span>connect<span class=\"p\">(</span>toppings_changed<span class=\"p\">,</span> sender<span class=\"o\">=</span>Pizza<span class=\"o\">.</span>toppings<span class=\"o\">.</span>through<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>p <span class=\"o\">=</span> Pizza<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>t <span class=\"o\">=</span> Topping<span class=\"o\">.</span>objects<span class=\"o\">.</span>create<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>p<span class=\"o\">.</span>toppings<span class=\"o\">.</span>add<span class=\"p\">(</span>t<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\">m2m_changed</code></a> handler (<code class=\"docutils literal notranslate\">toppings_changed</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\">sender</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">Pizza.toppings.through</code> (the intermediate m2m class)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">instance</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">p</code> (the <code class=\"docutils literal notranslate\">Pizza</code> instance being modified)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\">action</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">&quot;pre_add&quot;</code> (followed by a separate signal with <code class=\"docutils literal notranslate\">&quot;post_add&quot;</code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">reverse</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">False</code> (<code class=\"docutils literal notranslate\">Pizza</code> contains the\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</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\">model</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">Topping</code> (the class of the objects added to the\n<code class=\"docutils literal notranslate\">Pizza</code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">pk_set</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">{t.id}</code> (since only <code class=\"docutils literal notranslate\">Topping t</code> was added to the relation)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\">using</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">&quot;default&quot;</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>t<span class=\"o\">.</span>pizza_set<span class=\"o\">.</span>remove<span class=\"p\">(</span>p<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\">m2m_changed</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\">sender</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">Pizza.toppings.through</code> (the intermediate m2m class)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">instance</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">t</code> (the <code class=\"docutils literal notranslate\">Topping</code> instance being modified)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\">action</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">&quot;pre_remove&quot;</code> (followed by a separate signal with <code class=\"docutils literal notranslate\">&quot;post_remove&quot;</code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">reverse</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">True</code> (<code class=\"docutils literal notranslate\">Pizza</code> contains the\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/models/fields/#django.db.models.ManyToManyField\" title=\"django.db.models.ManyToManyField\"><code class=\"xref py py-class docutils literal notranslate\">ManyToManyField</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\">model</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">Pizza</code> (the class of the objects removed from the\n<code class=\"docutils literal notranslate\">Topping</code>)</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\">pk_set</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">{p.id}</code> (since only <code class=\"docutils literal notranslate\">Pizza p</code> was removed from the\nrelation)</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\">using</code></p></td>\n<td><p><code class=\"docutils literal notranslate\">&quot;default&quot;</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\">class_prepared</code><a class=\"heading-anchor\" href=\"#class-prepared\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">class_prepared</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.class_prepared\"><span class=\"visually-hidden\">Link para esta definição</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=\"/pt-br/1.10/ref/applications/#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\">AppConfig.ready()</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\">AppConfig.__init__()</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\">sender</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 para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Signals sent by <a class=\"reference internal\" href=\"/pt-br/1.10/ref/django-admin/\"><span class=\"doc\">django-admin</span></a>.</p>\n<section id=\"pre-migrate\">\n<h3><code class=\"docutils literal notranslate\">pre_migrate</code><a class=\"heading-anchor\" href=\"#pre-migrate\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">pre_migrate</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.pre_migrate\"><span class=\"visually-hidden\">Link para esta definição</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Sent by the <a class=\"reference internal\" href=\"/pt-br/1.10/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\">migrate</code></a> command before it starts to install an\napplication. It’s not emitted for applications that lack a <code class=\"docutils literal notranslate\">models</code> module.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>An <a class=\"reference internal\" href=\"/pt-br/1.10/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\">AppConfig</code></a> instance for the application about to\nbe migrated/synced.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">app_config</code></dt><dd><p>Same as <code class=\"docutils literal notranslate\">sender</code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">verbosity</code></dt><dd><p>Indicates how much information manage.py is printing on screen. See\nthe <a class=\"reference internal\" href=\"/pt-br/1.10/ref/django-admin/#cmdoption-verbosity\"><code class=\"xref std std-option docutils literal notranslate\">--verbosity</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\">pre_migrate</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\">interactive</code></dt><dd><p>If <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">True</code>, it’s safe to prompt the user to input\nthings on the command line. If <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">False</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=\"/pt-br/1.10/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.auth</code></a> app only prompts to create a\nsuperuser when <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">True</code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">using</code></dt><dd><p>The alias of database on which a command will operate.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">plan</code></dt><dd><aside class=\"version-note version-added\" data-version=\"1.10\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.10</p></aside>\n<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\">True</code>) or applied (<code class=\"docutils literal notranslate\">False</code>).</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">apps</code></dt><dd><aside class=\"version-note version-added\" data-version=\"1.10\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.10</p></aside>\n<p>An instance of <a class=\"reference internal\" href=\"/pt-br/1.10/ref/applications/#module-django.apps\" title=\"django.apps\"><code class=\"xref py py-data docutils literal notranslate\">Apps</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=\"/pt-br/1.10/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-attr docutils literal notranslate\">apps</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\">post_migrate</code><a class=\"heading-anchor\" href=\"#post-migrate\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.models.signals.</span><span class=\"sig-name descname\">post_migrate</span><a class=\"heading-anchor\" href=\"#django.db.models.signals.post_migrate\"><span class=\"visually-hidden\">Link para esta definição</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=\"/pt-br/1.10/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\">migrate</code></a> (even if no migrations are run) and\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/django-admin/#django-admin-flush\"><code class=\"xref std std-djadmin docutils literal notranslate\">flush</code></a> commands. It’s not emitted for applications that lack a\n<code class=\"docutils literal notranslate\">models</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=\"/pt-br/1.10/ref/django-admin/#django-admin-flush\"><code class=\"xref std std-djadmin docutils literal notranslate\">flush</code></a> command to fail if it runs during the\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/django-admin/#django-admin-migrate\"><code class=\"xref std std-djadmin docutils literal notranslate\">migrate</code></a> command.</p>\n<p>Arguments sent with this signal:</p>\n<dl>\n<dt><code class=\"docutils literal notranslate\">sender</code></dt><dd><p>An <a class=\"reference internal\" href=\"/pt-br/1.10/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\">AppConfig</code></a> instance for the application that was\njust installed.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">app_config</code></dt><dd><p>Same as <code class=\"docutils literal notranslate\">sender</code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">verbosity</code></dt><dd><p>Indicates how much information manage.py is printing on screen. See\nthe <a class=\"reference internal\" href=\"/pt-br/1.10/ref/django-admin/#cmdoption-verbosity\"><code class=\"xref std std-option docutils literal notranslate\">--verbosity</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\">post_migrate</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\">interactive</code></dt><dd><p>If <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">True</code>, it’s safe to prompt the user to input\nthings on the command line. If <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">False</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=\"/pt-br/1.10/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.auth</code></a> app only prompts to create a\nsuperuser when <code class=\"docutils literal notranslate\">interactive</code> is <code class=\"docutils literal notranslate\">True</code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">using</code></dt><dd><p>The database alias used for synchronization. Defaults to the <code class=\"docutils literal notranslate\">default</code>\ndatabase.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">plan</code></dt><dd><aside class=\"version-note version-added\" data-version=\"1.10\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.10</p></aside>\n<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\">True</code>) or applied (<code class=\"docutils literal notranslate\">False</code>).</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">apps</code></dt><dd><aside class=\"version-note version-added\" data-version=\"1.10\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.10</p></aside>\n<p>An instance of <a class=\"reference internal\" href=\"/pt-br/1.10/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-data docutils literal notranslate\">Apps</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=\"/pt-br/1.10/ref/applications/#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-attr docutils literal notranslate\">apps</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=\"/pt-br/1.10/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\">AppConfig</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=\"nn\">django.apps</span> <span class=\"kn\">import</span> AppConfig\n<span class=\"kn\">from</span> <span class=\"nn\">django.db.models.signals</span> <span class=\"kn\">import</span> post_migrate\n\n<span class=\"k\">def</span> <span class=\"nf\">my_callback</span><span class=\"p\">(</span>sender<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<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=\"nc\">MyAppConfig</span><span class=\"p\">(</span>AppConfig<span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">ready</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        post_migrate<span class=\"o\">.</span>connect<span class=\"p\">(</span>my_callback<span class=\"p\">,</span> sender<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\">Nota</p>\n<p>If you provide an <a class=\"reference internal\" href=\"/pt-br/1.10/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\">AppConfig</code></a> instance as the sender\nargument, please ensure that the signal is registered in\n<a class=\"reference internal\" href=\"/pt-br/1.10/ref/applications/#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\">ready()</code></a>. <code class=\"docutils literal notranslate\">AppConfig</code>s are recreated for\ntests that run with a modified set of <a class=\"reference internal\" href=\"/pt-br/1.10/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a> (such as\nwhen settings are overridden) and such signals should be connected for each\nnew <code class=\"docutils literal notranslate\">AppConfig</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 para este cabeçalho</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\">request_started</code><a class=\"heading-anchor\" href=\"#request-started\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.core.signals.</span><span class=\"sig-name descname\">request_started</span><a class=\"heading-anchor\" href=\"#django.core.signals.request_started\"><span class=\"visually-hidden\">Link para esta definição</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\">sender</code></dt><dd><p>The handler class – e.g. <code class=\"docutils literal notranslate\">django.core.handlers.wsgi.WsgiHandler</code> – that\nhandled the request.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">environ</code></dt><dd><p>The <code class=\"docutils literal notranslate\">environ</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\">request_finished</code><a class=\"heading-anchor\" href=\"#request-finished\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.core.signals.</span><span class=\"sig-name descname\">request_finished</span><a class=\"heading-anchor\" href=\"#django.core.signals.request_finished\"><span class=\"visually-hidden\">Link para esta definição</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<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>Some WSGI servers and middleware do not always call <code class=\"docutils literal notranslate\">close</code> on the\nresponse object after handling a request, most notably uWSGI prior to 1.2.6\nand Sentry’s error reporting middleware up to 2.0.7. In those cases this\nsignal isn’t sent at all. This can result in idle connections to database\nand memcache servers.</p>\n</aside>\n<p>Arguments sent with this signal:</p>\n<dl class=\"simple\">\n<dt><code class=\"docutils literal notranslate\">sender</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\">got_request_exception</code><a class=\"heading-anchor\" href=\"#got-request-exception\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.core.signals.</span><span class=\"sig-name descname\">got_request_exception</span><a class=\"heading-anchor\" href=\"#django.core.signals.got_request_exception\"><span class=\"visually-hidden\">Link para esta definição</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\">sender</code></dt><dd><p>The handler class, as above.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">request</code></dt><dd><p>The <a class=\"reference internal\" href=\"/pt-br/1.10/ref/request-response/#django.http.HttpRequest\" title=\"django.http.HttpRequest\"><code class=\"xref py py-class docutils literal notranslate\">HttpRequest</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 para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Signals only sent when <a class=\"reference internal\" href=\"/pt-br/1.10/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\">setting_changed</code><a class=\"heading-anchor\" href=\"#setting-changed\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.test.signals.</span><span class=\"sig-name descname\">setting_changed</span><a class=\"heading-anchor\" href=\"#django.test.signals.setting_changed\"><span class=\"visually-hidden\">Link para esta definição</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\">django.test.TestCase.settings()</code> context manager or the\n<a class=\"reference internal\" href=\"/pt-br/1.10/topics/testing/tools/#django.test.override_settings\" title=\"django.test.override_settings\"><code class=\"xref py py-func docutils literal notranslate\">django.test.override_settings()</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\">enter</code> argument to\ndistinguish between the two.</p>\n<p>You can also import this signal from <code class=\"docutils literal notranslate\">django.core.signals</code> to avoid importing\nfrom <code class=\"docutils literal notranslate\">django.test</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\">sender</code></dt><dd><p>The settings handler.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">setting</code></dt><dd><p>The name of the setting.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">value</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\">value</code> is <code class=\"docutils literal notranslate\">None</code>.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">enter</code></dt><dd><p>A boolean; <code class=\"docutils literal notranslate\">True</code> if the setting is applied, <code class=\"docutils literal notranslate\">False</code> if restored.</p>\n</dd>\n</dl>\n</section>\n<section id=\"template-rendered\">\n<h3><code class=\"docutils literal notranslate\">template_rendered</code><a class=\"heading-anchor\" href=\"#template-rendered\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.test.signals.</span><span class=\"sig-name descname\">template_rendered</span><a class=\"heading-anchor\" href=\"#django.test.signals.template_rendered\"><span class=\"visually-hidden\">Link para esta definição</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\">sender</code></dt><dd><p>The <a class=\"reference internal\" href=\"/pt-br/1.10/ref/templates/api/#django.template.Template\" title=\"django.template.Template\"><code class=\"xref py py-class docutils literal notranslate\">Template</code></a> object which was rendered.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">template</code></dt><dd><p>Same as sender</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">context</code></dt><dd><p>The <a class=\"reference internal\" href=\"/pt-br/1.10/ref/templates/api/#django.template.Context\" title=\"django.template.Context\"><code class=\"xref py py-class docutils literal notranslate\">Context</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 para este cabeçalho</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\">connection_created</code><a class=\"heading-anchor\" href=\"#connection-created\"><span class=\"visually-hidden\">Link para este cabeçalho</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\">django.db.backends.signals.</span><span class=\"sig-name descname\">connection_created</span><a class=\"heading-anchor\" href=\"#django.db.backends.signals.connection_created\"><span class=\"visually-hidden\">Link para esta definição</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\">sender</code></dt><dd><p>The database wrapper class – i.e.\n<code class=\"docutils literal notranslate\">django.db.backends.postgresql.DatabaseWrapper</code> or\n<code class=\"docutils literal notranslate\">django.db.backends.mysql.DatabaseWrapper</code>, etc.</p>\n</dd>\n<dt><code class=\"docutils literal notranslate\">connection</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":"Referência da API","url":"/pt-br/1.10/ref/"}],"prev":{"docname":"ref/settings","title":"Configurações","url":"/pt-br/1.10/ref/settings/"},"next":{"docname":"ref/templates/index","title":"Templates","url":"/pt-br/1.10/ref/templates/"},"formats":{"html":"/pt-br/1.10/ref/signals/","markdown":"/pt-br/1.10/ref/signals.md","json":"/pt-br/1.10/ref/signals.json"},"source":"https://github.com/django/django/blob/stable/1.10.x/docs/ref/signals.txt","official":"https://docs.djangoproject.com/pt-br/1.10/ref/signals/","inVersions":["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"],"inLocales":["en","fr","ja","id","pt-br","es","el","pl"]}