Grouping of model choices by field name.
Tested on Django 1.11 and Python 3.5
class ArticleForm(forms.Form):
articles = GroupedModelMultipleChoiceField(
group_by='category__name',
sort_choices_by='-title',
queryset=Article.objects.all(),
widget=forms.CheckboxSelectMultiple,
)
{{ form.articles }}
- group_by - groups choices by specific model field. Supports related fields. Required.
- sort_choices_by - sorts choices by specific model field. Support a reversed sort with adding to string start '-'. Optional.