Login

Snippets by denvaar

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

denvaar has posted 1 snippet.