djangosnippets.org: Latest snippets tagged with 'optgroup'https://djangosnippets.org/tags/optgroup/2016-07-04T10:52:13.296971-05:00ModelChoiceField & ModelMultipleChoiceField with optgroups
2016-07-04T10:52:13.296971-05:00denvaarhttps://djangosnippets.org/snippets/10573/<p>Fields that support HTML optgroups. Adapted from <a href="https://djangosnippets.org/snippets/1968/">this snippet</a> and updated to work with latest version of Django (1.9) and additional ModelMultipleChoiceField support added.</p>
<p>Example Usage:</p>
<pre><code>tag = GroupedModelChoiceField(queryset=Tag.objects.all(), group_by_field='parent')
positions = GroupedModelMultiChoiceField(queryset=Position.objects.all(),
group_by_field='agency')
</code></pre>
Freely redistributableChoice Field and Select Widget With Optional Optgroups
2007-04-24T18:09:20.969525-05:00leahculverhttps://djangosnippets.org/snippets/200/<p>Renders an select field with some optgroups. Some options can be outside the optgroup(s).</p>
<p>The options and labels should be in a tuple with ((label, choices),) where choices is a tuple ((key, value), (key2, value2)). If a label is null or blank, the options will not belong to an opt …</p>
Freely redistributable