def __init__(self, queryset, group_by_field='category', group_label=None, *args, **kwargs):
        """
        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
        """
        super(GroupedModelChoiceField, self).__init__(queryset, *args, **kwargs)
        self.group_by_field = group_by_field
        if group_label is None:
            self.group_label = lambda group: force_text(group)
        else:
            self.group_label = group_label

        # Need correct ordering, and category titles
        self.queryset = self.queryset.select_related().order_by('category', 'title')
def __init__ ( self , queryset , group_by_field = 'category' , group_label = None , * args , ** kwargs ) : super ( GroupedModelChoiceField , self ) . __init__ ( queryset , * args , ** kwargs ) self . group_by_field = group_by_field if group_label is None : self . group_label = lambda group : force_text ( group ) else : self . group_label = group_label self . queryset = self . queryset . select_related ( ) . order_by ( 'category' , 'title' )
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