Login

Tag "optgroup"

Snippet List

ModelChoiceField & ModelMultipleChoiceField with optgroups

Fields that support HTML optgroups. Adapted from [this snippet](https://djangosnippets.org/snippets/1968/) and updated to work with latest version of Django (1.9) and additional ModelMultipleChoiceField support added. Example Usage: tag = GroupedModelChoiceField(queryset=Tag.objects.all(), group_by_field='parent') positions = GroupedModelMultiChoiceField(queryset=Position.objects.all(), group_by_field='agency')

  • fields
  • optgroup
Read More

Choice Field and Select Widget With Optional Optgroups

Renders an select field with some optgroups. Some options can be outside the optgroup(s). 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 group.

  • newforms
  • widgets
  • select
  • optgroup
  • option
Read More

2 snippets posted so far.