djangosnippets.org: Latest snippets tagged with 'formset'http://djangosnippets.org/tags/formset/2015-08-25T12:59:04.764582-05:00Dynamic formset without javascript
2015-08-25T12:59:04.764582-05:00axelwasshttp://djangosnippets.org/snippets/10524/<p>If using javascript is not an option, you can use something like this code to have a variable number of subforms. </p>
<p>This code uses crispy-forms, but it is totally dispensable.</p>
Freely redistributableDynamically adding forms to a formset. OOP version.
2015-05-13T17:46:29.378832-05:00halfnibblehttp://djangosnippets.org/snippets/10484/<p><strong>What It Is</strong></p>
<p>This is a JavaScript-based solution to dynamically add and remove forms in formsets and inlineformsets. It requires jQuery.</p>
<p>Originally based on this Snippet: https://djangosnippets.org/snippets/1389/</p>
<p>I have done a lot of work to make it OO, and am using it in production on pages with multiple inlineformsets, and …</p>
Freely redistributableUnique field inline formset
2012-09-13T15:42:50.612941-05:00dcwatsonhttp://djangosnippets.org/snippets/2816/<p>This method will return an inline formset class that validates values across the given field are unique among all forms. For instance:</p>
<pre><code>ApprovedUserFormSet = inlineformset_factory(Request, ApprovedUser, formset=unique_field_formset('email'), form=ApprovedUserForm)
</code></pre>
<p>Will make sure all ApprovedUser objects created for the Request have unique "email" fields.</p>
Freely redistributableGenerating an InlineModelAdmin Form on the fly
2012-09-11T15:15:07.632371-05:00timbroderhttp://djangosnippets.org/snippets/2813/<p>Generate the form for an InlineModelAdmin. Usefull for ajaxing in a change in the Inline</p>
Freely redistributableHandles Inline Formsets and also "in-standard-way" normal forms
2012-02-27T00:09:48.970925-06:00sebnapihttp://djangosnippets.org/snippets/2695/<p>If you read the docstring and the example you should get a clue what this Code does. I didn't want a big function everytime that handles every specific form, formset combinations so this how i can add/edit Models with specific Forms given to the magic_handle_inlineformsets function. It also works for …</p>
Freely redistributableDynamical formsets
2011-11-16T05:28:28.774479-06:00I159http://djangosnippets.org/snippets/2603/<p>If you need dynamical formsets you can use <code>{{ empty_form }}</code> in template and even makeup it.</p>
Freely redistributablegrouper tag
2011-08-08T16:36:52.244628-05:00visgeanhttp://djangosnippets.org/snippets/2509/<p>I needed to display formset into table and I didn´t like solution I have found. So I have written this simple tag you can use it in templates like this:</p>
<p><code>{% for row in formset|square_it:6 %}
<tr>
<td>
</td>
{% for form in row %}
<td>
{% for field in …</code></p>
Freely redistributableDifferent number of extra formsets in add/change view of ModelAdmin.
2011-07-09T10:20:42.827597-05:00xormaghttp://djangosnippets.org/snippets/2483/<p>Small usability feature to show one number of additional formsets for new object & another for created.</p>
Freely redistributableDynamically alter the attributes of a formset
2010-05-31T00:35:46.486240-05:00cronosahttp://djangosnippets.org/snippets/2043/<p>Allow you to specify a "General case formset/modelformset" and then alter the attributes of that formset, specificly: extra, can_order, can_delete and max_num.</p>
<p>So you specify:</p>
<blockquote>
<blockquote>
<blockquote>
<p>formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O'))
and then you want to dynamically add multiple fields with javascript and save the new ones. By default a formset only has …</p></blockquote></blockquote></blockquote>
Freely redistributableComplex Formsets, Redux
2010-03-08T22:40:51.307107-06:00smagalahttp://djangosnippets.org/snippets/1955/<h1>Background</h1>
<p>Two years ago, Malcolm Tredinnick put up an excellent post about doing dynamic Django forms. There have been several excellent write-ups on it since - Google is your friend.</p>
<p>One year ago, I attempted to make a dynamic Formset - see <a href="http://www.djangosnippets.org/snippets/1290/">this snippet</a>. Malcolm posted a cleaner solution …</p>
Freely redistributableForm and FormSet that are defined dynamically with request-data
2010-01-10T05:26:09.140543-06:00Lacourhttp://djangosnippets.org/snippets/1863/<p>This is how you can access the user's request in the Form or FormSet definition, e.g. to define the choices of a ChoiceField dynamically.
Either you use it for a single Form or a whole FormSet, just pass the view's request into the Form or FormSet instantiation.</p>
Freely redistributablemultiple image upload with formset example
2009-12-31T00:38:46.594569-06:00dodolbokshttp://djangosnippets.org/snippets/1848/<p>example formset views for multiple image upload</p>
<p>hope its useful ... </p>
Freely redistributableArbitrary length formset
2009-09-01T15:48:38.587460-05:00Rupehttp://djangosnippets.org/snippets/1711/<p>A formset class where you can add forms as you discover the need within your code. There is also the ability to add ManagmentForm fields.</p>
<p>If you ever found yourself in a situation where 1) you have repeated forms that need to be displayed in different locations, or 2) if …</p>
Freely redistributablePrinting inline formsets as UL / P
2009-08-25T06:47:23.293151-05:00ikkehttp://djangosnippets.org/snippets/1698/<p>By default all forms created using inlineformset_factory are displayed as tables (because there is only a .as_table method) and there are no .as_p or .as_ul methods in them, so you need to do that by hand.</p>
Freely redistributableMaking a django inline (model) formset really tabular
2009-04-15T20:00:46.499263-05:00fnlhttp://djangosnippets.org/snippets/1442/<p>As there is no straight way to re-produce the real tabular inline formsets you get in django-admin, here is how this template has to look like if you do it form your own formsets generated from formset factories.</p>
Freely redistributable