Images in list form, How?

Hello!

Dear masters! Please help me with this question.

models.py

class New_tables(models.Model):

TYPEBET_CHOICES = (
    ('1','up'),
    ('0', 'down'),
 
)

type_bet = models.IntegerField(choices=TYPEBET_CHOICES)

form.py

type_bet = forms.TypedChoiceField(choices=New_tables.TYPEBET_CHOICES)

how to make sure that when you select from the list, there are not “up” and “down”, but that instead of them a picture is displayed, preloaded in /media/ ?

Off the top of my head, I’m inclined to believe that you would need to override the option_template_name attribute of the Select widget being used by that field.

I believe you may need to do this by subclassing the Select widget with your own class, and then specifying your widget class as the widget for that field.

1 Like