{"title":"Formsets","version":"6.1","locale":"it","docname":"topics/forms/formsets","url":"/it/6.1/topics/forms/formsets/","canonical":"https://djangodocs.dev/it/6.1/topics/forms/formsets/","summary":"A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid.","html":"<h1>Formsets<a class=\"heading-anchor\" href=\"#formsets\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">BaseFormSet</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A formset is a layer of abstraction to work with multiple forms on the same\npage. It can be best compared to a data grid. Let’s say you have the following\nform:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django</span> <span class=\"kn\">import</span> forms\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">ArticleForm</span><span class=\"p\">(</span>forms<span class=\"o\">.</span>Form<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    title <span class=\"o\">=</span> forms<span class=\"o\">.</span>CharField<span class=\"p\">()</span>\n<span class=\"gp\">... </span>    pub_date <span class=\"o\">=</span> forms<span class=\"o\">.</span>DateField<span class=\"p\">()</span>\n<span class=\"gp\">...</span>\n</code></pre></div>\n<p>You might want to allow the user to create several articles at once. To create\na formset out of an <code class=\"docutils literal notranslate\">ArticleForm</code> you would do:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">)</span>\n</code></pre></div>\n<p>You now have created a formset class named <code class=\"docutils literal notranslate\">ArticleFormSet</code>.\nInstantiating the formset gives you the ability to iterate over the forms\nin the formset and display them as you would with a regular form:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">()</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-title&quot; id=&quot;id_form-0-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-pub_date&quot; id=&quot;id_form-0-pub_date&quot;&gt;&lt;/div&gt;</span>\n</code></pre></div>\n<p>As you can see it only displayed one empty form. The number of empty forms\nthat is displayed is controlled by the <code class=\"docutils literal notranslate\">extra</code> parameter. By default,\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a> defines one extra form; the\nfollowing example will create a formset class to display two blank forms:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> extra<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Formsets can be iterated and indexed, accessing forms in the order they were\ncreated. You can reorder the forms by overriding the default\n<a class=\"reference external\" href=\"https://docs.python.org/3/reference/datamodel.html#object.__iter__\" title=\"(in Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">__iter__()</code></a> and <a class=\"reference external\" href=\"https://docs.python.org/3/reference/datamodel.html#object.__getitem__\" title=\"(in Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">__getitem__()</code></a> methods if needed.\n(For more information on implementing these methods, see the\n<a class=\"reference external\" href=\"https://docs.python.org/3/glossary.html#term-sequence\" title=\"(in Python v3.14)\"><span class=\"xref std std-term\">Python documentation on sequences</span></a>.)</p>\n<section id=\"using-initial-data-with-a-formset\">\n<span id=\"formsets-initial-data\"></span><h2>Using initial data with a formset<a class=\"heading-anchor\" href=\"#using-initial-data-with-a-formset\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Initial data is what drives the main usability of a formset. As shown above\nyou can define the number of extra forms. What this means is that you are\ntelling the formset how many additional forms to show in addition to the\nnumber of forms it generates from the initial data. Let’s take a look at an\nexample:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">import</span> <span class=\"nn\">datetime</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> extra<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    initial<span class=\"o\">=</span><span class=\"p\">[</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span>\n<span class=\"gp\">... </span>            <span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Django is now open source&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>            <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"o\">.</span>today<span class=\"p\">(),</span>\n<span class=\"gp\">... </span>        <span class=\"p\">}</span>\n<span class=\"gp\">... </span>    <span class=\"p\">]</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-title&quot; value=&quot;Django is now open source&quot; id=&quot;id_form-0-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-pub_date&quot; value=&quot;2023-02-11&quot; id=&quot;id_form-0-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-1-title&quot; id=&quot;id_form-1-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-1-pub_date&quot; id=&quot;id_form-1-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-2-title&quot; id=&quot;id_form-2-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-2-pub_date&quot; id=&quot;id_form-2-pub_date&quot;&gt;&lt;/div&gt;</span>\n</code></pre></div>\n<p>There are now a total of three forms showing above. One for the initial data\nthat was passed in and two extra forms. Also note that we are passing in a\nlist of dictionaries as the initial data.</p>\n<p>If you use an <code class=\"docutils literal notranslate\">initial</code> for displaying a formset, you should pass the same\n<code class=\"docutils literal notranslate\">initial</code> when processing that formset’s submission so that the formset can\ndetect which forms were changed by the user. For example, you might have\nsomething like: <code class=\"docutils literal notranslate\">ArticleFormSet(request.POST, initial=[...])</code>.</p>\n<aside class=\"admonition admonition-seealso\" role=\"note\">\n<p class=\"admonition-title\">Vedi anche</p>\n<p><a class=\"reference internal\" href=\"/it/6.1/topics/forms/modelforms/#model-formsets\"><span class=\"std std-ref\">Creating formsets from models with model formsets</span></a>.</p>\n</aside>\n</section>\n<section id=\"limiting-the-maximum-number-of-forms\">\n<span id=\"formsets-max-num\"></span><h2>Limiting the maximum number of forms<a class=\"heading-anchor\" href=\"#limiting-the-maximum-number-of-forms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <code class=\"docutils literal notranslate\">max_num</code> parameter to <a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a>\ngives you the ability to limit the number of forms the formset will display:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> extra<span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">,</span> max_num<span class=\"o\">=</span><span class=\"mi\">1</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">()</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-title&quot; id=&quot;id_form-0-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-pub_date&quot; id=&quot;id_form-0-pub_date&quot;&gt;&lt;/div&gt;</span>\n</code></pre></div>\n<p>If the value of <code class=\"docutils literal notranslate\">max_num</code> is greater than the number of existing items in the\ninitial data, up to <code class=\"docutils literal notranslate\">extra</code> additional blank forms will be added to the\nformset, so long as the total number of forms does not exceed <code class=\"docutils literal notranslate\">max_num</code>. For\nexample, if <code class=\"docutils literal notranslate\">extra=2</code> and <code class=\"docutils literal notranslate\">max_num=2</code> and the formset is initialized with\none <code class=\"docutils literal notranslate\">initial</code> item, a form for the initial item and one blank form will be\ndisplayed.</p>\n<p>If the number of items in the initial data exceeds <code class=\"docutils literal notranslate\">max_num</code>, all initial\ndata forms will be displayed regardless of the value of <code class=\"docutils literal notranslate\">max_num</code> and no\nextra forms will be displayed. For example, if <code class=\"docutils literal notranslate\">extra=3</code> and <code class=\"docutils literal notranslate\">max_num=1</code>\nand the formset is initialized with two initial items, two forms with the\ninitial data will be displayed.</p>\n<p>A <code class=\"docutils literal notranslate\">max_num</code> value of <code class=\"docutils literal notranslate\">None</code> (the default) puts a high limit on the number\nof forms displayed (1000). In practice this is equivalent to no limit.</p>\n<p>By default, <code class=\"docutils literal notranslate\">max_num</code> only affects how many forms are displayed and does not\naffect validation. If <code class=\"docutils literal notranslate\">validate_max=True</code> is passed to the\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a>, then <code class=\"docutils literal notranslate\">max_num</code> will affect\nvalidation. See <a class=\"reference internal\" href=\"#validate-max\"><span class=\"std std-ref\">validate_max</span></a>.</p>\n</section>\n<section id=\"limiting-the-maximum-number-of-instantiated-forms\">\n<span id=\"formsets-absolute-max\"></span><h2>Limiting the maximum number of instantiated forms<a class=\"heading-anchor\" href=\"#limiting-the-maximum-number-of-instantiated-forms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <code class=\"docutils literal notranslate\">absolute_max</code> parameter to <a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a> allows limiting the\nnumber of forms that can be instantiated when supplying <code class=\"docutils literal notranslate\">POST</code> data. This\nprotects against memory exhaustion attacks using forged <code class=\"docutils literal notranslate\">POST</code> requests:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms.formsets</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> absolute_max<span class=\"o\">=</span><span class=\"mi\">1500</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1501&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">len</span><span class=\"p\">(</span>formset<span class=\"o\">.</span>forms<span class=\"p\">)</span>\n<span class=\"go\">1500</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>non_form_errors<span class=\"p\">()</span>\n<span class=\"go\">[&#39;Please submit at most 1000 forms.&#39;]</span>\n</code></pre></div>\n<p>When <code class=\"docutils literal notranslate\">absolute_max</code> is <code class=\"docutils literal notranslate\">None</code>, it defaults to <code class=\"docutils literal notranslate\">max_num + 1000</code>. (If\n<code class=\"docutils literal notranslate\">max_num</code> is <code class=\"docutils literal notranslate\">None</code>, it defaults to <code class=\"docutils literal notranslate\">2000</code>).</p>\n<p>If <code class=\"docutils literal notranslate\">absolute_max</code> is less than <code class=\"docutils literal notranslate\">max_num</code>, a <code class=\"docutils literal notranslate\">ValueError</code> will be raised.</p>\n</section>\n<section id=\"formset-validation\">\n<h2>Formset validation<a class=\"heading-anchor\" href=\"#formset-validation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Validation with a formset is almost identical to a regular <code class=\"docutils literal notranslate\">Form</code>. There is\nan <code class=\"docutils literal notranslate\">is_valid</code> method on the formset to provide a convenient way to validate\nall forms in the formset:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">True</span>\n</code></pre></div>\n<p>We passed in no data to the formset which is resulting in a valid form. The\nformset is smart enough to ignore extra forms that were not changed. If we\nprovide an invalid article:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1904-06-16&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># &lt;-- this date is missing but required</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>errors\n<span class=\"go\">[{}, {&#39;pub_date&#39;: [&#39;This field is required.&#39;]}]</span>\n</code></pre></div>\n<p>As we can see, <code class=\"docutils literal notranslate\">formset.errors</code> is a list whose entries correspond to the\nforms in the formset. Validation was performed for each of the two forms, and\nthe expected error message appears for the second item.</p>\n<p>Just like when using a normal <code class=\"docutils literal notranslate\">Form</code>, each field in a formset’s forms may\ninclude HTML attributes such as <code class=\"docutils literal notranslate\">maxlength</code> for browser validation. However,\nform fields of formsets won’t include the <code class=\"docutils literal notranslate\">required</code> attribute as that\nvalidation may be incorrect when adding and deleting forms.</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.total_error_count\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">total_error_count</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.total_error_count\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>To check how many errors there are in the formset, we can use the\n<code class=\"docutils literal notranslate\">total_error_count</code> method:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"c1\"># Using the previous example</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>errors\n<span class=\"go\">[{}, {&#39;pub_date&#39;: [&#39;This field is required.&#39;]}]</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"nb\">len</span><span class=\"p\">(</span>formset<span class=\"o\">.</span>errors<span class=\"p\">)</span>\n<span class=\"go\">2</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>total_error_count<span class=\"p\">()</span>\n<span class=\"go\">1</span>\n</code></pre></div>\n<p>We can also check if form data differs from the initial data (i.e. the form was\nsent without any data):</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>has_changed<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n</code></pre></div>\n<section id=\"understanding-the-managementform\">\n<span id=\"id1\"></span><h3>Understanding the <code class=\"docutils literal notranslate\">ManagementForm</code><a class=\"heading-anchor\" href=\"#understanding-the-managementform\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You may have noticed the additional data (<code class=\"docutils literal notranslate\">form-TOTAL_FORMS</code>,\n<code class=\"docutils literal notranslate\">form-INITIAL_FORMS</code>) that was required in the formset’s data above. This\ndata is required for the <code class=\"docutils literal notranslate\">ManagementForm</code>. This form is used by the formset\nto manage the collection of forms contained in the formset. If you don’t\nprovide this management data, the formset will be invalid:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n</code></pre></div>\n<p>It is used to keep track of how many form instances are being displayed. If you\nare adding new forms via JavaScript, you should increment the count fields in\nthis form as well. On the other hand, if you are using JavaScript to allow\ndeletion of existing objects, then you need to ensure the ones being removed\nare properly marked for deletion by including <code class=\"docutils literal notranslate\">form-#-DELETE</code> in the <code class=\"docutils literal notranslate\">POST</code>\ndata. It is expected that all forms are present in the <code class=\"docutils literal notranslate\">POST</code> data\nregardless.</p>\n<p>The management form is available as an attribute of the formset\nitself. When rendering a formset in a template, you can include all\nthe management data by rendering <code class=\"docutils literal notranslate\">{{ my_formset.management_form }}</code>\n(substituting the name of your formset as appropriate).</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>As well as the <code class=\"docutils literal notranslate\">form-TOTAL_FORMS</code> and <code class=\"docutils literal notranslate\">form-INITIAL_FORMS</code> fields shown\nin the examples here, the management form also includes\n<code class=\"docutils literal notranslate\">form-MIN_NUM_FORMS</code> and <code class=\"docutils literal notranslate\">form-MAX_NUM_FORMS</code> fields. They are output\nwith the rest of the management form, but only for the convenience of\nclient-side code. These fields are not required and so are not shown in\nthe example <code class=\"docutils literal notranslate\">POST</code> data.</p>\n</aside>\n</section>\n<section id=\"total-form-count-and-initial-form-count\">\n<h3><code class=\"docutils literal notranslate\">total_form_count</code> and <code class=\"docutils literal notranslate\">initial_form_count</code><a class=\"heading-anchor\" href=\"#total-form-count-and-initial-form-count\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><code class=\"docutils literal notranslate\">BaseFormSet</code> has a couple of methods that are closely related to the\n<code class=\"docutils literal notranslate\">ManagementForm</code>, <code class=\"docutils literal notranslate\">total_form_count</code> and <code class=\"docutils literal notranslate\">initial_form_count</code>.</p>\n<p><code class=\"docutils literal notranslate\">total_form_count</code> returns the total number of forms in this formset.\n<code class=\"docutils literal notranslate\">initial_form_count</code> returns the number of forms in the formset that were\npre-filled, and is also used to determine how many forms are required. You\nwill probably never need to override either of these methods, so please be\nsure you understand what they do before doing so.</p>\n</section>\n<section id=\"empty-form\">\n<span id=\"id2\"></span><h3><code class=\"docutils literal notranslate\">empty_form</code><a class=\"heading-anchor\" href=\"#empty-form\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><code class=\"docutils literal notranslate\">BaseFormSet</code> provides an additional attribute <code class=\"docutils literal notranslate\">empty_form</code> which returns\na form instance with a prefix of <code class=\"docutils literal notranslate\">__prefix__</code> for easier use in dynamic\nforms with JavaScript.</p>\n</section>\n<section id=\"error-messages\">\n<span id=\"formsets-error-messages\"></span><h3><code class=\"docutils literal notranslate\">error_messages</code><a class=\"heading-anchor\" href=\"#error-messages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The <code class=\"docutils literal notranslate\">error_messages</code> argument lets you override the default messages that the\nformset will raise. Pass in a dictionary with keys matching the error messages\nyou want to override. Error message keys include <code class=\"docutils literal notranslate\">'too_few_forms'</code>,\n<code class=\"docutils literal notranslate\">'too_many_forms'</code>, and <code class=\"docutils literal notranslate\">'missing_management_form'</code>. The\n<code class=\"docutils literal notranslate\">'too_few_forms'</code> and <code class=\"docutils literal notranslate\">'too_many_forms'</code> error messages may contain\n<code class=\"docutils literal notranslate\">%(num)d</code>, which will be replaced with <code class=\"docutils literal notranslate\">min_num</code> and <code class=\"docutils literal notranslate\">max_num</code>,\nrespectively.</p>\n<p>For example, here is the default error message when the\nmanagement form is missing:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">({})</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>non_form_errors<span class=\"p\">()</span>\n<span class=\"go\">[&#39;ManagementForm data is missing or has been tampered with. Missing fields: form-TOTAL_FORMS, form-INITIAL_FORMS. You may need to file a bug report if the issue persists.&#39;]</span>\n</code></pre></div>\n<p>And here is a custom error message:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    <span class=\"p\">{},</span> error_messages<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;missing_management_form&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Sorry, something went wrong.&quot;</span><span class=\"p\">}</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>non_form_errors<span class=\"p\">()</span>\n<span class=\"go\">[&#39;Sorry, something went wrong.&#39;]</span>\n</code></pre></div>\n</section>\n<section id=\"custom-formset-validation\">\n<h3>Custom formset validation<a class=\"heading-anchor\" href=\"#custom-formset-validation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>A formset has a <code class=\"docutils literal notranslate\">clean</code> method similar to the one on a <code class=\"docutils literal notranslate\">Form</code> class. This\nis where you define your own validation that works at the formset level:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.core.exceptions</span> <span class=\"kn\">import</span> ValidationError\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    <span class=\"k\">def</span> <span class=\"nf\">clean</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n<span class=\"gp\">... </span>        <span class=\"sd\">&quot;&quot;&quot;Checks that no two articles have the same title.&quot;&quot;&quot;</span>\n<span class=\"gp\">... </span>        <span class=\"k\">if</span> <span class=\"nb\">any</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span>errors<span class=\"p\">):</span>\n<span class=\"gp\">... </span>            <span class=\"c1\"># Don&#39;t bother validating the formset unless each form is valid on its own</span>\n<span class=\"gp\">... </span>            <span class=\"k\">return</span>\n<span class=\"gp\">... </span>        titles <span class=\"o\">=</span> <span class=\"nb\">set</span><span class=\"p\">()</span>\n<span class=\"gp\">... </span>        <span class=\"k\">for</span> form <span class=\"ow\">in</span> <span class=\"bp\">self</span><span class=\"o\">.</span>forms<span class=\"p\">:</span>\n<span class=\"gp\">... </span>            <span class=\"k\">if</span> <span class=\"bp\">self</span><span class=\"o\">.</span>can_delete <span class=\"ow\">and</span> <span class=\"bp\">self</span><span class=\"o\">.</span>_should_delete_form<span class=\"p\">(</span>form<span class=\"p\">):</span>\n<span class=\"gp\">... </span>                <span class=\"k\">continue</span>\n<span class=\"gp\">... </span>            title <span class=\"o\">=</span> form<span class=\"o\">.</span>cleaned_data<span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">... </span>            <span class=\"k\">if</span> title <span class=\"ow\">in</span> titles<span class=\"p\">:</span>\n<span class=\"gp\">... </span>                <span class=\"k\">raise</span> ValidationError<span class=\"p\">(</span><span class=\"s2\">&quot;Articles in a set must have distinct titles.&quot;</span><span class=\"p\">)</span>\n<span class=\"gp\">... </span>            titles<span class=\"o\">.</span>add<span class=\"p\">(</span>title<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1904-06-16&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1912-06-23&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>errors\n<span class=\"go\">[{}, {}]</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>non_form_errors<span class=\"p\">()</span>\n<span class=\"go\">[&#39;Articles in a set must have distinct titles.&#39;]</span>\n</code></pre></div>\n<p>The formset <code class=\"docutils literal notranslate\">clean</code> method is called after all the <code class=\"docutils literal notranslate\">Form.clean</code> methods\nhave been called. The errors will be found using the <code class=\"docutils literal notranslate\">non_form_errors()</code>\nmethod on the formset.</p>\n<p>Non-form errors will be rendered with an additional class of <code class=\"docutils literal notranslate\">nonform</code> to\nhelp distinguish them from form-specific errors. For example,\n<code class=\"docutils literal notranslate\">{{ formset.non_form_errors }}</code> would look like:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</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=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">class</span><span class=\"o\">=</span><span class=\"s\">&quot;errorlist nonform&quot;</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>Articles in a set must have distinct titles.<span class=\"p\">&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"validating-the-number-of-forms-in-a-formset\">\n<h2>Validating the number of forms in a formset<a class=\"heading-anchor\" href=\"#validating-the-number-of-forms-in-a-formset\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django provides a couple ways to validate the minimum or maximum number of\nsubmitted forms. Applications which need more customizable validation of the\nnumber of forms should use custom formset validation.</p>\n<section id=\"validate-max\">\n<span id=\"id3\"></span><h3><code class=\"docutils literal notranslate\">validate_max</code><a class=\"heading-anchor\" href=\"#validate-max\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If <code class=\"docutils literal notranslate\">validate_max=True</code> is passed to\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a>, validation will also check\nthat the number of forms in the data set, minus those marked for\ndeletion, is less than or equal to <code class=\"docutils literal notranslate\">max_num</code>.</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> max_num<span class=\"o\">=</span><span class=\"mi\">1</span><span class=\"p\">,</span> validate_max<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1904-06-16&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test 2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1912-06-23&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>errors\n<span class=\"go\">[{}, {}]</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>non_form_errors<span class=\"p\">()</span>\n<span class=\"go\">[&#39;Please submit at most 1 form.&#39;]</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">validate_max=True</code> validates against <code class=\"docutils literal notranslate\">max_num</code> strictly even if\n<code class=\"docutils literal notranslate\">max_num</code> was exceeded because the amount of initial data supplied was\nexcessive.</p>\n<p>The error message can be customized by passing the <code class=\"docutils literal notranslate\">'too_many_forms'</code> message\nto the <a class=\"reference internal\" href=\"#formsets-error-messages\"><span class=\"std std-ref\">error_messages</span></a> argument.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>Regardless of <code class=\"docutils literal notranslate\">validate_max</code>, if the number of forms in a data set\nexceeds <code class=\"docutils literal notranslate\">absolute_max</code>, then the form will fail to validate as if\n<code class=\"docutils literal notranslate\">validate_max</code> were set, and additionally only the first <code class=\"docutils literal notranslate\">absolute_max</code>\nforms will be validated. The remainder will be truncated entirely. This is\nto protect against memory exhaustion attacks using forged POST requests.\nSee <a class=\"reference internal\" href=\"#formsets-absolute-max\"><span class=\"std std-ref\">Limiting the maximum number of instantiated forms</span></a>.</p>\n</aside>\n</section>\n<section id=\"validate-min\">\n<h3><code class=\"docutils literal notranslate\">validate_min</code><a class=\"heading-anchor\" href=\"#validate-min\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If <code class=\"docutils literal notranslate\">validate_min=True</code> is passed to\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a>, validation will also check\nthat the number of forms in the data set, minus those marked for\ndeletion, is greater than or equal to <code class=\"docutils literal notranslate\">min_num</code>.</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> min_num<span class=\"o\">=</span><span class=\"mi\">3</span><span class=\"p\">,</span> validate_min<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1904-06-16&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Test 2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1912-06-23&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>data<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span>\n<span class=\"go\">False</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>errors\n<span class=\"go\">[{}, {}]</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset<span class=\"o\">.</span>non_form_errors<span class=\"p\">()</span>\n<span class=\"go\">[&#39;Please submit at least 3 forms.&#39;]</span>\n</code></pre></div>\n<p>The error message can be customized by passing the <code class=\"docutils literal notranslate\">'too_few_forms'</code> message\nto the <a class=\"reference internal\" href=\"#formsets-error-messages\"><span class=\"std std-ref\">error_messages</span></a> argument.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>Regardless of <code class=\"docutils literal notranslate\">validate_min</code>, if a formset contains no data, then\n<code class=\"docutils literal notranslate\">extra + min_num</code> empty forms will be displayed.</p>\n</aside>\n</section>\n</section>\n<section id=\"dealing-with-ordering-and-deletion-of-forms\">\n<h2>Dealing with ordering and deletion of forms<a class=\"heading-anchor\" href=\"#dealing-with-ordering-and-deletion-of-forms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <a class=\"reference internal\" href=\"/it/6.1/ref/forms/formsets/#django.forms.formsets.formset_factory\" title=\"django.forms.formsets.formset_factory\"><code class=\"xref py py-func docutils literal notranslate\">formset_factory()</code></a> provides two optional\nparameters <code class=\"docutils literal notranslate\">can_order</code> and <code class=\"docutils literal notranslate\">can_delete</code> to help with ordering of forms in\nformsets and deletion of forms from a formset.</p>\n<section id=\"can-order\">\n<h3><code class=\"docutils literal notranslate\">can_order</code><a class=\"heading-anchor\" href=\"#can-order\"><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.forms.formsets.BaseFormSet.can_order\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">can_order</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.can_order\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Default: <code class=\"docutils literal notranslate\">False</code></p>\n<p>Lets you create a formset with the ability to order:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> can_order<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    initial<span class=\"o\">=</span><span class=\"p\">[</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #1&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">10</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #2&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">11</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>    <span class=\"p\">]</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-title&quot; value=&quot;Article #1&quot; id=&quot;id_form-0-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-pub_date&quot; value=&quot;2008-05-10&quot; id=&quot;id_form-0-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-ORDER&quot;&gt;Order:&lt;/label&gt;&lt;input type=&quot;number&quot; name=&quot;form-0-ORDER&quot; value=&quot;1&quot; id=&quot;id_form-0-ORDER&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-1-title&quot; value=&quot;Article #2&quot; id=&quot;id_form-1-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-1-pub_date&quot; value=&quot;2008-05-11&quot; id=&quot;id_form-1-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-ORDER&quot;&gt;Order:&lt;/label&gt;&lt;input type=&quot;number&quot; name=&quot;form-1-ORDER&quot; value=&quot;2&quot; id=&quot;id_form-1-ORDER&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-2-title&quot; id=&quot;id_form-2-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-2-pub_date&quot; id=&quot;id_form-2-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-ORDER&quot;&gt;Order:&lt;/label&gt;&lt;input type=&quot;number&quot; name=&quot;form-2-ORDER&quot; id=&quot;id_form-2-ORDER&quot;&gt;&lt;/div&gt;</span>\n</code></pre></div>\n<p>This adds an additional field to each form. This new field is named <code class=\"docutils literal notranslate\">ORDER</code>\nand is an <code class=\"docutils literal notranslate\">forms.IntegerField</code>. For the forms that came from the initial\ndata it automatically assigned them a numeric value. Let’s look at what will\nhappen when the user changes these values:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;3&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #1&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2008-05-10&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-ORDER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2008-05-11&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-ORDER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;1&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-2-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #3&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-2-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2008-05-01&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-2-ORDER&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;0&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    data<span class=\"p\">,</span>\n<span class=\"gp\">... </span>    initial<span class=\"o\">=</span><span class=\"p\">[</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #1&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">10</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #2&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">11</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>    <span class=\"p\">],</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"o\">.</span>ordered_forms<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"o\">.</span>cleaned_data<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">{&#39;title&#39;: &#39;Article #3&#39;, &#39;pub_date&#39;: datetime.date(2008, 5, 1), &#39;ORDER&#39;: 0}</span>\n<span class=\"go\">{&#39;title&#39;: &#39;Article #2&#39;, &#39;pub_date&#39;: datetime.date(2008, 5, 11), &#39;ORDER&#39;: 1}</span>\n<span class=\"go\">{&#39;title&#39;: &#39;Article #1&#39;, &#39;pub_date&#39;: datetime.date(2008, 5, 10), &#39;ORDER&#39;: 2}</span>\n</code></pre></div>\n<p><a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet\" title=\"django.forms.formsets.BaseFormSet\"><code class=\"xref py py-class docutils literal notranslate\">BaseFormSet</code></a> also provides an\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.ordering_widget\" title=\"django.forms.formsets.BaseFormSet.ordering_widget\"><code class=\"xref py py-attr docutils literal notranslate\">ordering_widget</code></a> attribute and\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.get_ordering_widget\" title=\"django.forms.formsets.BaseFormSet.get_ordering_widget\"><code class=\"xref py py-meth docutils literal notranslate\">get_ordering_widget()</code></a> method that\ncontrol the widget used with\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.can_order\" title=\"django.forms.formsets.BaseFormSet.can_order\"><code class=\"xref py py-attr docutils literal notranslate\">can_order</code></a>.</p>\n<section id=\"ordering-widget\">\n<h4><code class=\"docutils literal notranslate\">ordering_widget</code><a class=\"heading-anchor\" href=\"#ordering-widget\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.ordering_widget\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">ordering_widget</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.ordering_widget\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Default: <a class=\"reference internal\" href=\"/it/6.1/ref/forms/widgets/#django.forms.NumberInput\" title=\"django.forms.NumberInput\"><code class=\"xref py py-class docutils literal notranslate\">NumberInput</code></a></p>\n<p>Set <code class=\"docutils literal notranslate\">ordering_widget</code> to specify the widget class to be used with\n<code class=\"docutils literal notranslate\">can_order</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet<span class=\"p\">,</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    ordering_widget <span class=\"o\">=</span> HiddenInput\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    ArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">,</span> can_order<span class=\"o\">=</span><span class=\"kc\">True</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"get-ordering-widget\">\n<h4><code class=\"docutils literal notranslate\">get_ordering_widget</code><a class=\"heading-anchor\" href=\"#get-ordering-widget\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.get_ordering_widget\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">get_ordering_widget</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.get_ordering_widget\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Override <code class=\"docutils literal notranslate\">get_ordering_widget()</code> if you need to provide a widget instance for\nuse with <code class=\"docutils literal notranslate\">can_order</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet<span class=\"p\">,</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    <span class=\"k\">def</span> <span class=\"nf\">get_ordering_widget</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n<span class=\"gp\">... </span>        <span class=\"k\">return</span> HiddenInput<span class=\"p\">(</span>attrs<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;ordering&quot;</span><span class=\"p\">})</span>\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    ArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">,</span> can_order<span class=\"o\">=</span><span class=\"kc\">True</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"can-delete\">\n<h3><code class=\"docutils literal notranslate\">can_delete</code><a class=\"heading-anchor\" href=\"#can-delete\"><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.forms.formsets.BaseFormSet.can_delete\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">can_delete</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.can_delete\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Default: <code class=\"docutils literal notranslate\">False</code></p>\n<p>Lets you create a formset with the ability to select forms for deletion:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> can_delete<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    initial<span class=\"o\">=</span><span class=\"p\">[</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #1&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">10</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #2&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">11</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>    <span class=\"p\">]</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-title&quot; value=&quot;Article #1&quot; id=&quot;id_form-0-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-pub_date&quot; value=&quot;2008-05-10&quot; id=&quot;id_form-0-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-DELETE&quot;&gt;Delete:&lt;/label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;form-0-DELETE&quot; id=&quot;id_form-0-DELETE&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-1-title&quot; value=&quot;Article #2&quot; id=&quot;id_form-1-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-1-pub_date&quot; value=&quot;2008-05-11&quot; id=&quot;id_form-1-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-1-DELETE&quot;&gt;Delete:&lt;/label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;form-1-DELETE&quot; id=&quot;id_form-1-DELETE&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-2-title&quot; id=&quot;id_form-2-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-2-pub_date&quot; id=&quot;id_form-2-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-2-DELETE&quot;&gt;Delete:&lt;/label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;form-2-DELETE&quot; id=&quot;id_form-2-DELETE&quot;&gt;&lt;/div&gt;</span>\n</code></pre></div>\n<p>Similar to <code class=\"docutils literal notranslate\">can_order</code> this adds a new field to each form named <code class=\"docutils literal notranslate\">DELETE</code>\nand is a <code class=\"docutils literal notranslate\">forms.BooleanField</code>. When data comes through marking any of the\ndelete fields you can access them with <code class=\"docutils literal notranslate\">deleted_forms</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>data <span class=\"o\">=</span> <span class=\"p\">{</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-TOTAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;3&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-INITIAL_FORMS&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #1&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2008-05-10&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-0-DELETE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;on&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #2&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;2008-05-11&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-1-DELETE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-2-title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-2-pub_date&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span>    <span class=\"s2\">&quot;form-2-DELETE&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span>\n<span class=\"gp\">... </span><span class=\"p\">}</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    data<span class=\"p\">,</span>\n<span class=\"gp\">... </span>    initial<span class=\"o\">=</span><span class=\"p\">[</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #1&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">10</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>        <span class=\"p\">{</span><span class=\"s2\">&quot;title&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Article #2&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;pub_date&quot;</span><span class=\"p\">:</span> datetime<span class=\"o\">.</span>date<span class=\"p\">(</span><span class=\"mi\">2008</span><span class=\"p\">,</span> <span class=\"mi\">5</span><span class=\"p\">,</span> <span class=\"mi\">11</span><span class=\"p\">)},</span>\n<span class=\"gp\">... </span>    <span class=\"p\">],</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"p\">[</span>form<span class=\"o\">.</span>cleaned_data <span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"o\">.</span>deleted_forms<span class=\"p\">]</span>\n<span class=\"go\">[{&#39;title&#39;: &#39;Article #1&#39;, &#39;pub_date&#39;: datetime.date(2008, 5, 10), &#39;DELETE&#39;: True}]</span>\n</code></pre></div>\n<p>If you are using a <a class=\"reference internal\" href=\"/it/6.1/topics/forms/modelforms/#django.forms.models.BaseModelFormSet\" title=\"django.forms.models.BaseModelFormSet\"><code class=\"xref py py-class docutils literal notranslate\">ModelFormSet</code></a>,\nmodel instances for deleted forms will be deleted when you call\n<code class=\"docutils literal notranslate\">formset.save()</code>.</p>\n<p>If you call <code class=\"docutils literal notranslate\">formset.save(commit=False)</code>, objects will not be deleted\nautomatically. You’ll need to call <code class=\"docutils literal notranslate\">delete()</code> on each of the\n<a class=\"reference internal\" href=\"/it/6.1/topics/forms/modelforms/#django.forms.models.BaseModelFormSet.deleted_objects\" title=\"django.forms.models.BaseModelFormSet.deleted_objects\"><code class=\"xref py py-attr docutils literal notranslate\">formset.deleted_objects</code></a> to actually delete\nthem:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span>instances <span class=\"o\">=</span> formset<span class=\"o\">.</span>save<span class=\"p\">(</span>commit<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> obj <span class=\"ow\">in</span> formset<span class=\"o\">.</span>deleted_objects<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    obj<span class=\"o\">.</span>delete<span class=\"p\">()</span>\n<span class=\"gp\">...</span>\n</code></pre></div>\n<p>On the other hand, if you are using a plain <code class=\"docutils literal notranslate\">FormSet</code>, it’s up to you to\nhandle <code class=\"docutils literal notranslate\">formset.deleted_forms</code>, perhaps in your formset’s <code class=\"docutils literal notranslate\">save()</code> method,\nas there’s no general notion of what it means to delete a form.</p>\n<p><a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet\" title=\"django.forms.formsets.BaseFormSet\"><code class=\"xref py py-class docutils literal notranslate\">BaseFormSet</code></a> also provides a\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.deletion_widget\" title=\"django.forms.formsets.BaseFormSet.deletion_widget\"><code class=\"xref py py-attr docutils literal notranslate\">deletion_widget</code></a> attribute and\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.get_deletion_widget\" title=\"django.forms.formsets.BaseFormSet.get_deletion_widget\"><code class=\"xref py py-meth docutils literal notranslate\">get_deletion_widget()</code></a> method that\ncontrol the widget used with\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.can_delete\" title=\"django.forms.formsets.BaseFormSet.can_delete\"><code class=\"xref py py-attr docutils literal notranslate\">can_delete</code></a>.</p>\n<section id=\"deletion-widget\">\n<h4><code class=\"docutils literal notranslate\">deletion_widget</code><a class=\"heading-anchor\" href=\"#deletion-widget\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.deletion_widget\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">deletion_widget</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.deletion_widget\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Default: <a class=\"reference internal\" href=\"/it/6.1/ref/forms/widgets/#django.forms.CheckboxInput\" title=\"django.forms.CheckboxInput\"><code class=\"xref py py-class docutils literal notranslate\">CheckboxInput</code></a></p>\n<p>Set <code class=\"docutils literal notranslate\">deletion_widget</code> to specify the widget class to be used with\n<code class=\"docutils literal notranslate\">can_delete</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet<span class=\"p\">,</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    deletion_widget <span class=\"o\">=</span> HiddenInput\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    ArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">,</span> can_delete<span class=\"o\">=</span><span class=\"kc\">True</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"get-deletion-widget\">\n<h4><code class=\"docutils literal notranslate\">get_deletion_widget</code><a class=\"heading-anchor\" href=\"#get-deletion-widget\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.get_deletion_widget\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">get_deletion_widget</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.get_deletion_widget\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Override <code class=\"docutils literal notranslate\">get_deletion_widget()</code> if you need to provide a widget instance for\nuse with <code class=\"docutils literal notranslate\">can_delete</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet<span class=\"p\">,</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    <span class=\"k\">def</span> <span class=\"nf\">get_deletion_widget</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n<span class=\"gp\">... </span>        <span class=\"k\">return</span> HiddenInput<span class=\"p\">(</span>attrs<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;deletion&quot;</span><span class=\"p\">})</span>\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>\n<span class=\"gp\">... </span>    ArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">,</span> can_delete<span class=\"o\">=</span><span class=\"kc\">True</span>\n<span class=\"gp\">... </span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"can-delete-extra\">\n<h3><code class=\"docutils literal notranslate\">can_delete_extra</code><a class=\"heading-anchor\" href=\"#can-delete-extra\"><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.forms.formsets.BaseFormSet.can_delete_extra\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">can_delete_extra</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.can_delete_extra\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Default: <code class=\"docutils literal notranslate\">True</code></p>\n<p>While setting <code class=\"docutils literal notranslate\">can_delete=True</code>, specifying <code class=\"docutils literal notranslate\">can_delete_extra=False</code> will\nremove the option to delete extra forms.</p>\n</section>\n</section>\n<section id=\"adding-additional-fields-to-a-formset\">\n<h2>Adding additional fields to a formset<a class=\"heading-anchor\" href=\"#adding-additional-fields-to-a-formset\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>If you need to add additional fields to the formset this can be easily\naccomplished. The formset base class provides an <code class=\"docutils literal notranslate\">add_fields</code> method. You\ncan override this method to add your own fields or even redefine the default\nfields/attributes of the order and deletion fields:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    <span class=\"k\">def</span> <span class=\"nf\">add_fields</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> form<span class=\"p\">,</span> index<span class=\"p\">):</span>\n<span class=\"gp\">... </span>        <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span>add_fields<span class=\"p\">(</span>form<span class=\"p\">,</span> index<span class=\"p\">)</span>\n<span class=\"gp\">... </span>        form<span class=\"o\">.</span>fields<span class=\"p\">[</span><span class=\"s2\">&quot;my_field&quot;</span><span class=\"p\">]</span> <span class=\"o\">=</span> forms<span class=\"o\">.</span>CharField<span class=\"p\">()</span>\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">()</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">for</span> form <span class=\"ow\">in</span> formset<span class=\"p\">:</span>\n<span class=\"gp\">... </span>    <span class=\"nb\">print</span><span class=\"p\">(</span>form<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-title&quot;&gt;Title:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-title&quot; id=&quot;id_form-0-title&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-pub_date&quot;&gt;Pub date:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-pub_date&quot; id=&quot;id_form-0-pub_date&quot;&gt;&lt;/div&gt;</span>\n<span class=\"go\">&lt;div&gt;&lt;label for=&quot;id_form-0-my_field&quot;&gt;My field:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;form-0-my_field&quot; id=&quot;id_form-0-my_field&quot;&gt;&lt;/div&gt;</span>\n</code></pre></div>\n</section>\n<section id=\"passing-custom-parameters-to-formset-forms\">\n<span id=\"custom-formset-form-kwargs\"></span><h2>Passing custom parameters to formset forms<a class=\"heading-anchor\" href=\"#passing-custom-parameters-to-formset-forms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Sometimes your form class takes custom parameters, like <code class=\"docutils literal notranslate\">MyArticleForm</code>.\nYou can pass this parameter when instantiating the formset:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">MyArticleForm</span><span class=\"p\">(</span>ArticleForm<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    <span class=\"k\">def</span> <span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span>args<span class=\"p\">,</span> user<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n<span class=\"gp\">... </span>        <span class=\"bp\">self</span><span class=\"o\">.</span>user <span class=\"o\">=</span> user\n<span class=\"gp\">... </span>        <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span><span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">)</span>\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>MyArticleForm<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>form_kwargs<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;user&quot;</span><span class=\"p\">:</span> request<span class=\"o\">.</span>user<span class=\"p\">})</span>\n</code></pre></div>\n<p>The <code class=\"docutils literal notranslate\">form_kwargs</code> may also depend on the specific form instance. The formset\nbase class provides a <code class=\"docutils literal notranslate\">get_form_kwargs</code> method. The method takes a single\nargument - the index of the form in the formset. The index is <code class=\"docutils literal notranslate\">None</code> for the\n<a class=\"reference internal\" href=\"#empty-form\"><span class=\"std std-ref\">empty_form</span></a>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</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=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> BaseFormSet\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.forms</span> <span class=\"kn\">import</span> formset_factory\n\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"k\">class</span> <span class=\"nc\">BaseArticleFormSet</span><span class=\"p\">(</span>BaseFormSet<span class=\"p\">):</span>\n<span class=\"gp\">... </span>    <span class=\"k\">def</span> <span class=\"nf\">get_form_kwargs</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> index<span class=\"p\">):</span>\n<span class=\"gp\">... </span>        kwargs <span class=\"o\">=</span> <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span>get_form_kwargs<span class=\"p\">(</span>index<span class=\"p\">)</span>\n<span class=\"gp\">... </span>        kwargs<span class=\"p\">[</span><span class=\"s2\">&quot;custom_kwarg&quot;</span><span class=\"p\">]</span> <span class=\"o\">=</span> index\n<span class=\"gp\">... </span>        <span class=\"k\">return</span> kwargs\n<span class=\"gp\">...</span>\n\n<span class=\"gp\">&gt;&gt;&gt; </span>ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>MyArticleForm<span class=\"p\">,</span> formset<span class=\"o\">=</span>BaseArticleFormSet<span class=\"p\">)</span>\n<span class=\"gp\">&gt;&gt;&gt; </span>formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">()</span>\n</code></pre></div>\n</section>\n<section id=\"customizing-a-formset-s-prefix\">\n<span id=\"formset-prefix\"></span><h2>Customizing a formset’s prefix<a class=\"heading-anchor\" href=\"#customizing-a-formset-s-prefix\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In the rendered HTML, formsets include a prefix on each field’s name. By\ndefault, the prefix is <code class=\"docutils literal notranslate\">'form'</code>, but it can be customized using the formset’s\n<code class=\"docutils literal notranslate\">prefix</code> argument.</p>\n<p>For example, in the default case, you might see:</p>\n<div class=\"code-block\" data-language=\"html\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Html</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=\"Html code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">label</span> <span class=\"na\">for</span><span class=\"o\">=</span><span class=\"s\">&quot;id_form-0-title&quot;</span><span class=\"p\">&gt;</span>Title:<span class=\"p\">&lt;/</span><span class=\"nt\">label</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">input</span> <span class=\"na\">type</span><span class=\"o\">=</span><span class=\"s\">&quot;text&quot;</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">&quot;form-0-title&quot;</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">&quot;id_form-0-title&quot;</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>But with <code class=\"docutils literal notranslate\">ArticleFormset(prefix='article')</code> that becomes:</p>\n<div class=\"code-block\" data-language=\"html\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Html</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=\"Html code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">label</span> <span class=\"na\">for</span><span class=\"o\">=</span><span class=\"s\">&quot;id_article-0-title&quot;</span><span class=\"p\">&gt;</span>Title:<span class=\"p\">&lt;/</span><span class=\"nt\">label</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">input</span> <span class=\"na\">type</span><span class=\"o\">=</span><span class=\"s\">&quot;text&quot;</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">&quot;article-0-title&quot;</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">&quot;id_article-0-title&quot;</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>This is useful if you want to <a class=\"reference internal\" href=\"#multiple-formsets-in-view\"><span class=\"std std-ref\">use more than one formset in a view</span></a>.</p>\n</section>\n<section id=\"using-a-formset-in-views-and-templates\">\n<span id=\"formset-rendering\"></span><h2>Using a formset in views and templates<a class=\"heading-anchor\" href=\"#using-a-formset-in-views-and-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Formsets have the following attributes and methods associated with rendering:</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.renderer\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">renderer</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.renderer\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Specifies the <a class=\"reference internal\" href=\"/it/6.1/ref/forms/renderers/\"><span class=\"doc\">renderer</span></a> to use for the\nformset. Defaults to the renderer specified by the <a class=\"reference internal\" href=\"/it/6.1/ref/settings/#std-setting-FORM_RENDERER\"><code class=\"xref std std-setting docutils literal notranslate\">FORM_RENDERER</code></a>\nsetting.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.template_name\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">template_name</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.template_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the template rendered if the formset is cast into a string,\ne.g. via <code class=\"docutils literal notranslate\">print(formset)</code> or in a template via <code class=\"docutils literal notranslate\">{{ formset }}</code>.</p>\n<p>By default, a property returning the value of the renderer’s\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/renderers/#django.forms.renderers.BaseRenderer.formset_template_name\" title=\"django.forms.renderers.BaseRenderer.formset_template_name\"><code class=\"xref py py-attr docutils literal notranslate\">formset_template_name</code></a>. You may\nset it as a string template name in order to override that for a particular\nformset class.</p>\n<p>This template will be used to render the formset’s management form, and\nthen each form in the formset as per the template defined by the form’s\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/api/#django.forms.Form.template_name\" title=\"django.forms.Form.template_name\"><code class=\"xref py py-attr docutils literal notranslate\">template_name</code></a>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.template_name_div\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">template_name_div</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.template_name_div\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the template used when calling <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_div\" title=\"django.forms.formsets.BaseFormSet.as_div\"><code class=\"xref py py-meth docutils literal notranslate\">as_div()</code></a>. By default this\nis <code class=\"docutils literal notranslate\">&quot;django/forms/formsets/div.html&quot;</code>. This template renders the\nformset’s management form and then each form in the formset as per the\nform’s <a class=\"reference internal\" href=\"/it/6.1/ref/forms/api/#django.forms.Form.as_div\" title=\"django.forms.Form.as_div\"><code class=\"xref py py-meth docutils literal notranslate\">as_div()</code></a> method.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.template_name_p\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">template_name_p</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.template_name_p\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the template used when calling <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_p\" title=\"django.forms.formsets.BaseFormSet.as_p\"><code class=\"xref py py-meth docutils literal notranslate\">as_p()</code></a>. By default this\nis <code class=\"docutils literal notranslate\">&quot;django/forms/formsets/p.html&quot;</code>. This template renders the formset’s\nmanagement form and then each form in the formset as per the form’s\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/api/#django.forms.Form.as_p\" title=\"django.forms.Form.as_p\"><code class=\"xref py py-meth docutils literal notranslate\">as_p()</code></a> method.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.template_name_table\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">template_name_table</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.template_name_table\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the template used when calling <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_table\" title=\"django.forms.formsets.BaseFormSet.as_table\"><code class=\"xref py py-meth docutils literal notranslate\">as_table()</code></a>. By default\nthis is <code class=\"docutils literal notranslate\">&quot;django/forms/formsets/table.html&quot;</code>. This template renders the\nformset’s management form and then each form in the formset as per the\nform’s <a class=\"reference internal\" href=\"/it/6.1/ref/forms/api/#django.forms.Form.as_table\" title=\"django.forms.Form.as_table\"><code class=\"xref py py-meth docutils literal notranslate\">as_table()</code></a> method.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.template_name_ul\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">template_name_ul</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.template_name_ul\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the template used when calling <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_ul\" title=\"django.forms.formsets.BaseFormSet.as_ul\"><code class=\"xref py py-meth docutils literal notranslate\">as_ul()</code></a>. By default this\nis <code class=\"docutils literal notranslate\">&quot;django/forms/formsets/ul.html&quot;</code>. This template renders the formset’s\nmanagement form and then each form in the formset as per the form’s\n<a class=\"reference internal\" href=\"/it/6.1/ref/forms/api/#django.forms.Form.as_ul\" title=\"django.forms.Form.as_ul\"><code class=\"xref py py-meth docutils literal notranslate\">as_ul()</code></a> method.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.get_context\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">get_context</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.get_context\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the context for rendering a formset in a template.</p>\n<p>The available context is:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">formset</code> : The instance of the formset.</p></li>\n</ul>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.render\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">render</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">template_name<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">context<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">renderer<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.render\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The render method is called by <code class=\"docutils literal notranslate\">__str__</code> as well as the <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_div\" title=\"django.forms.formsets.BaseFormSet.as_div\"><code class=\"xref py py-meth docutils literal notranslate\">as_div()</code></a>,\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_p\" title=\"django.forms.formsets.BaseFormSet.as_p\"><code class=\"xref py py-meth docutils literal notranslate\">as_p()</code></a>, <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_ul\" title=\"django.forms.formsets.BaseFormSet.as_ul\"><code class=\"xref py py-meth docutils literal notranslate\">as_ul()</code></a>, and <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.as_table\" title=\"django.forms.formsets.BaseFormSet.as_table\"><code class=\"xref py py-meth docutils literal notranslate\">as_table()</code></a> methods. All arguments\nare optional and will default to:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">template_name</code>: <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.template_name\" title=\"django.forms.formsets.BaseFormSet.template_name\"><code class=\"xref py py-attr docutils literal notranslate\">template_name</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">context</code>: Value returned by <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.get_context\" title=\"django.forms.formsets.BaseFormSet.get_context\"><code class=\"xref py py-meth docutils literal notranslate\">get_context()</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">renderer</code>: Value returned by <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.renderer\" title=\"django.forms.formsets.BaseFormSet.renderer\"><code class=\"xref py py-attr docutils literal notranslate\">renderer</code></a></p></li>\n</ul>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.as_div\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">as_div</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.as_div\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Renders the formset with the <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.template_name_div\" title=\"django.forms.formsets.BaseFormSet.template_name_div\"><code class=\"xref py py-attr docutils literal notranslate\">template_name_div</code></a> template.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.as_p\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">as_p</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.as_p\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Renders the formset with the <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.template_name_p\" title=\"django.forms.formsets.BaseFormSet.template_name_p\"><code class=\"xref py py-attr docutils literal notranslate\">template_name_p</code></a> template.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.as_table\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">as_table</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.as_table\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Renders the formset with the <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.template_name_table\" title=\"django.forms.formsets.BaseFormSet.template_name_table\"><code class=\"xref py py-attr docutils literal notranslate\">template_name_table</code></a> template.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.forms.formsets.BaseFormSet.as_ul\">\n<span class=\"sig-prename descclassname\">BaseFormSet.</span><span class=\"sig-name descname\">as_ul</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.forms.formsets.BaseFormSet.as_ul\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Renders the formset with the <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.template_name_ul\" title=\"django.forms.formsets.BaseFormSet.template_name_ul\"><code class=\"xref py py-attr docutils literal notranslate\">template_name_ul</code></a> template.</p>\n</dd></dl>\n\n<p>Using a formset inside a view is not very different from using a regular\n<code class=\"docutils literal notranslate\">Form</code> class. The only thing you will want to be aware of is making sure to\nuse the management form inside the template. Let’s look at a sample view:</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.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"kn\">from</span> <span class=\"nn\">django.shortcuts</span> <span class=\"kn\">import</span> render\n<span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm\n\n\n<span class=\"k\">def</span> <span class=\"nf\">manage_articles</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">)</span>\n    <span class=\"k\">if</span> request<span class=\"o\">.</span>method <span class=\"o\">==</span> <span class=\"s2\">&quot;POST&quot;</span><span class=\"p\">:</span>\n        formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>request<span class=\"o\">.</span>POST<span class=\"p\">,</span> request<span class=\"o\">.</span>FILES<span class=\"p\">)</span>\n        <span class=\"k\">if</span> formset<span class=\"o\">.</span>is_valid<span class=\"p\">():</span>\n            <span class=\"c1\"># do something with the formset.cleaned_data</span>\n            <span class=\"k\">pass</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">()</span>\n    <span class=\"k\">return</span> render<span class=\"p\">(</span>request<span class=\"p\">,</span> <span class=\"s2\">&quot;manage_articles.html&quot;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s2\">&quot;formset&quot;</span><span class=\"p\">:</span> formset<span class=\"p\">})</span>\n</code></pre></div>\n<p>The <code class=\"docutils literal notranslate\">manage_articles.html</code> template might look like this:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</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=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">form</span> <span class=\"na\">method</span><span class=\"o\">=</span><span class=\"s\">&quot;post&quot;</span><span class=\"p\">&gt;</span>\n    <span class=\"cp\">{{</span> <span class=\"nv\">formset.management_form</span> <span class=\"cp\">}}</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">table</span><span class=\"p\">&gt;</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">for</span> <span class=\"nv\">form</span> <span class=\"k\">in</span> <span class=\"nv\">formset</span> <span class=\"cp\">%}</span>\n        <span class=\"cp\">{{</span> <span class=\"nv\">form</span> <span class=\"cp\">}}</span>\n        <span class=\"cp\">{%</span> <span class=\"k\">endfor</span> <span class=\"cp\">%}</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">table</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">form</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>However there’s a slight shortcut for the above by letting the formset itself\ndeal with the management form:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</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=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">form</span> <span class=\"na\">method</span><span class=\"o\">=</span><span class=\"s\">&quot;post&quot;</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">table</span><span class=\"p\">&gt;</span>\n        <span class=\"cp\">{{</span> <span class=\"nv\">formset</span> <span class=\"cp\">}}</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">table</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">form</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>The above ends up calling the <a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.render\" title=\"django.forms.formsets.BaseFormSet.render\"><code class=\"xref py py-meth docutils literal notranslate\">BaseFormSet.render()</code></a> method on the formset\nclass. This renders the formset using the template specified by the\n<a class=\"reference internal\" href=\"#django.forms.formsets.BaseFormSet.template_name\" title=\"django.forms.formsets.BaseFormSet.template_name\"><code class=\"xref py py-attr docutils literal notranslate\">template_name</code></a> attribute. Similar to forms, by default the\nformset will be rendered <code class=\"docutils literal notranslate\">as_div</code>, with other helper methods of <code class=\"docutils literal notranslate\">as_p</code>,\n<code class=\"docutils literal notranslate\">as_ul</code>, and <code class=\"docutils literal notranslate\">as_table</code> being available. The rendering of the formset can\nbe customized by specifying the <code class=\"docutils literal notranslate\">template_name</code> attribute, or more generally\nby <a class=\"reference internal\" href=\"/it/6.1/ref/forms/renderers/#overriding-built-in-formset-templates\"><span class=\"std std-ref\">overriding the default template</span></a>.</p>\n<section id=\"manually-rendered-can-delete-and-can-order\">\n<span id=\"id4\"></span><h3>Manually rendered <code class=\"docutils literal notranslate\">can_delete</code> and <code class=\"docutils literal notranslate\">can_order</code><a class=\"heading-anchor\" href=\"#manually-rendered-can-delete-and-can-order\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you manually render fields in the template, you can render\n<code class=\"docutils literal notranslate\">can_delete</code> parameter with <code class=\"docutils literal notranslate\">{{ form.DELETE }}</code>:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</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=\"Django template code\"><code><span class=\"p\">&lt;</span><span class=\"nt\">form</span> <span class=\"na\">method</span><span class=\"o\">=</span><span class=\"s\">&quot;post&quot;</span><span class=\"p\">&gt;</span>\n    <span class=\"cp\">{{</span> <span class=\"nv\">formset.management_form</span> <span class=\"cp\">}}</span>\n    <span class=\"cp\">{%</span> <span class=\"k\">for</span> <span class=\"nv\">form</span> <span class=\"k\">in</span> <span class=\"nv\">formset</span> <span class=\"cp\">%}</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n            <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">form.title</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n            <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">form.pub_date</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n            <span class=\"cp\">{%</span> <span class=\"k\">if</span> <span class=\"nv\">formset.can_delete</span> <span class=\"cp\">%}</span>\n                <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span><span class=\"cp\">{{</span> <span class=\"nv\">form.DELETE</span> <span class=\"cp\">}}</span><span class=\"p\">&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n            <span class=\"cp\">{%</span> <span class=\"k\">endif</span> <span class=\"cp\">%}</span>\n        <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n    <span class=\"cp\">{%</span> <span class=\"k\">endfor</span> <span class=\"cp\">%}</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">form</span><span class=\"p\">&gt;</span>\n</code></pre></div>\n<p>Similarly, if the formset has the ability to order (<code class=\"docutils literal notranslate\">can_order=True</code>), it is\npossible to render it with <code class=\"docutils literal notranslate\">{{ form.ORDER }}</code>.</p>\n</section>\n<section id=\"using-more-than-one-formset-in-a-view\">\n<span id=\"multiple-formsets-in-view\"></span><h3>Using more than one formset in a view<a class=\"heading-anchor\" href=\"#using-more-than-one-formset-in-a-view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>You are able to use more than one formset in a view if you like. Formsets\nborrow much of its behavior from forms. With that said you are able to use\n<code class=\"docutils literal notranslate\">prefix</code> to prefix formset form field names with a given value to allow\nmore than one formset to be sent to a view without name clashing. Let’s take\na look at how this might be accomplished:</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.forms</span> <span class=\"kn\">import</span> formset_factory\n<span class=\"kn\">from</span> <span class=\"nn\">django.shortcuts</span> <span class=\"kn\">import</span> render\n<span class=\"kn\">from</span> <span class=\"nn\">myapp.forms</span> <span class=\"kn\">import</span> ArticleForm<span class=\"p\">,</span> BookForm\n\n\n<span class=\"k\">def</span> <span class=\"nf\">manage_articles</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    ArticleFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>ArticleForm<span class=\"p\">)</span>\n    BookFormSet <span class=\"o\">=</span> formset_factory<span class=\"p\">(</span>BookForm<span class=\"p\">)</span>\n    <span class=\"k\">if</span> request<span class=\"o\">.</span>method <span class=\"o\">==</span> <span class=\"s2\">&quot;POST&quot;</span><span class=\"p\">:</span>\n        article_formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>request<span class=\"o\">.</span>POST<span class=\"p\">,</span> request<span class=\"o\">.</span>FILES<span class=\"p\">,</span> prefix<span class=\"o\">=</span><span class=\"s2\">&quot;articles&quot;</span><span class=\"p\">)</span>\n        book_formset <span class=\"o\">=</span> BookFormSet<span class=\"p\">(</span>request<span class=\"o\">.</span>POST<span class=\"p\">,</span> request<span class=\"o\">.</span>FILES<span class=\"p\">,</span> prefix<span class=\"o\">=</span><span class=\"s2\">&quot;books&quot;</span><span class=\"p\">)</span>\n        <span class=\"k\">if</span> article_formset<span class=\"o\">.</span>is_valid<span class=\"p\">()</span> <span class=\"ow\">and</span> book_formset<span class=\"o\">.</span>is_valid<span class=\"p\">():</span>\n            <span class=\"c1\"># do something with the cleaned_data on the formsets.</span>\n            <span class=\"k\">pass</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        article_formset <span class=\"o\">=</span> ArticleFormSet<span class=\"p\">(</span>prefix<span class=\"o\">=</span><span class=\"s2\">&quot;articles&quot;</span><span class=\"p\">)</span>\n        book_formset <span class=\"o\">=</span> BookFormSet<span class=\"p\">(</span>prefix<span class=\"o\">=</span><span class=\"s2\">&quot;books&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">return</span> render<span class=\"p\">(</span>\n        request<span class=\"p\">,</span>\n        <span class=\"s2\">&quot;manage_articles.html&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;article_formset&quot;</span><span class=\"p\">:</span> article_formset<span class=\"p\">,</span>\n            <span class=\"s2\">&quot;book_formset&quot;</span><span class=\"p\">:</span> book_formset<span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n<p>You would then render the formsets as normal. It is important to point out\nthat you need to pass <code class=\"docutils literal notranslate\">prefix</code> on both the POST and non-POST cases so that\nit is rendered and processed correctly.</p>\n<p>Each formset’s <a class=\"reference internal\" href=\"#formset-prefix\"><span class=\"std std-ref\">prefix</span></a> replaces the default <code class=\"docutils literal notranslate\">form</code>\nprefix that’s added to each field’s <code class=\"docutils literal notranslate\">name</code> and <code class=\"docutils literal notranslate\">id</code> HTML attributes.</p>\n</section>\n</section>","rootId":"formsets","toc":[{"title":"Using initial data with a formset","anchor":"using-initial-data-with-a-formset","children":[]},{"title":"Limiting the maximum number of forms","anchor":"limiting-the-maximum-number-of-forms","children":[]},{"title":"Limiting the maximum number of instantiated forms","anchor":"limiting-the-maximum-number-of-instantiated-forms","children":[]},{"title":"Formset validation","anchor":"formset-validation","children":[{"title":"Understanding the ManagementForm","anchor":"understanding-the-managementform","children":[]},{"title":"total_form_count and initial_form_count","anchor":"total-form-count-and-initial-form-count","children":[]},{"title":"empty_form","anchor":"empty-form","children":[]},{"title":"error_messages","anchor":"error-messages","children":[]},{"title":"Custom formset validation","anchor":"custom-formset-validation","children":[]}]},{"title":"Validating the number of forms in a formset","anchor":"validating-the-number-of-forms-in-a-formset","children":[{"title":"validate_max","anchor":"validate-max","children":[]},{"title":"validate_min","anchor":"validate-min","children":[]}]},{"title":"Dealing with ordering and deletion of forms","anchor":"dealing-with-ordering-and-deletion-of-forms","children":[{"title":"can_order","anchor":"can-order","children":[{"title":"ordering_widget","anchor":"ordering-widget","children":[]},{"title":"get_ordering_widget","anchor":"get-ordering-widget","children":[]}]},{"title":"can_delete","anchor":"can-delete","children":[{"title":"deletion_widget","anchor":"deletion-widget","children":[]},{"title":"get_deletion_widget","anchor":"get-deletion-widget","children":[]}]},{"title":"can_delete_extra","anchor":"can-delete-extra","children":[]}]},{"title":"Adding additional fields to a formset","anchor":"adding-additional-fields-to-a-formset","children":[]},{"title":"Passing custom parameters to formset forms","anchor":"passing-custom-parameters-to-formset-forms","children":[]},{"title":"Customizing a formset’s prefix","anchor":"customizing-a-formset-s-prefix","children":[]},{"title":"Using a formset in views and templates","anchor":"using-a-formset-in-views-and-templates","children":[{"title":"Manually rendered can_delete and can_order","anchor":"manually-rendered-can-delete-and-can-order","children":[]},{"title":"Using more than one formset in a view","anchor":"using-more-than-one-formset-in-a-view","children":[]}]}],"breadcrumbs":[{"docname":"topics/index","title":"Using Django","url":"/it/6.1/topics/"},{"docname":"topics/forms/index","title":"Working with forms","url":"/it/6.1/topics/forms/"}],"prev":{"docname":"topics/forms/index","title":"Working with forms","url":"/it/6.1/topics/forms/"},"next":{"docname":"topics/forms/modelforms","title":"Creating forms from models","url":"/it/6.1/topics/forms/modelforms/"},"formats":{"html":"/it/6.1/topics/forms/formsets/","markdown":"/it/6.1/topics/forms/formsets.md","json":"/it/6.1/topics/forms/formsets.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/topics/forms/formsets.txt","official":"https://docs.djangoproject.com/it/6.1/topics/forms/formsets/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}