def __init__(self, queryset, group_by_field, group_label=None, *args, **kwargs):
super(GroupedModelChoiceField, self).__init__(queryset, *args, **kwargs)<EOL>self.group_by_field = group_by_field<EOL>if group_label is None:<EOL><INDENT>self.group_label = lambda group: group<EOL><DEDENT>else:<EOL><INDENT>self.group_label = group_label<EOL><DEDENT>
group_by_field is the name of a field on the model
group_label is a function to return a label for each choice group