'Exclude unselected self.choices before calling the parent method.
Used by Django>=1.10.'

def optgroups(self, name, value, attrs=None):

    selected_choices = [six.text_type(c) for c in value if c]
    all_choices = copy.copy(self.choices)
    if self.url:
        self.filter_choices_to_render(selected_choices)
    elif self.placeholder:
        self.choices.insert(0, (None, ''))
    result = super(WidgetMixin, self).optgroups(name, value, attrs)
    self.choices = all_choices
    return result
