code: def optgroups(self, name, value, attrs=None):
          
          groups = []
          has_selected = False
          if attrs is None:
              attrs = {}
  
          for index, (option_value, option_label, sort_fields) in enumerate(
                  chain(self.choices)):
  
              # Set tree attributes
              attrs['data-tree-id'] = sort_fields[0]
              attrs['data-left-value'] = sort_fields[1]
  
              subgroup = []
              subindex = None
              choices = [(option_value, option_label)]
              groups.append((None, subgroup, index))
  
              for subvalue, sublabel in choices:
                  selected = (
                      force_text(subvalue) in value and
                      (has_selected is False or self.allow_multiple_selected)
                  )
                  if selected is True and has_selected is False:
                      has_selected = True
                  subgroup.append(self.create_option(
                      name, subvalue, sublabel, selected, index,
                      subindex=subindex, attrs=attrs,
                  ))
  
          return groups
docs: Return a list of optgroups for this widget.