in your code, after call the super class initializer, set the choices as below:
class TooltipSelectWidget(Select) :
def __init__(self, *args, **kwargs) :
super().__init__(*args, **kwargs)
self.choices = [] # List of 2-tuple values
If you look at the code of the __init__
of the Select
class (Base class for your custom widget) you can get intuition about why this is the solution:
class Select(Widget):
allow_multiple_selected = False
def __init__(self, attrs=None, choices=()):
super(Select, self).__init__(attrs)
# choices can be any iterable, but we may need to render this widget
# multiple times. Thus, collapse it into a list so it can be consumed
# more than once.
self.choices = list(choices)
A better approach is to have your custom choices by default in your
class TooltipSelectWidget(Select) :
CUSTOM_CHOICES = () # Modify at will.
def __init__(self, attrs=None, choices=CUSTOM_CHOICES) :
super().__init__(attrs=attrs, choices=choices)