code: def optgroups(self, name, value, attrs=None):
          
          default = (None, [], 0)
          groups = [default]
          # We must add at least one 'selected' option or widget will show nothing.
          for v in value:
              if not v:
                  continue
              if hasattr(self.choices, 'queryset'):
                  item = self.choices.queryset.filter(id=v).first()
                  if item:
                      label = item.name
                  else:
                      label = force_text(v)
              else:
                  label = force_text(v)
              subgroup = default[1]
              subgroup.append(self.create_option(
                  name, v, label, True, 0,
                  subindex=None, attrs=attrs,
              ))
          return groups
docs: Return a list of optgroups for this widget.