I have the following model
class Color(models.Model):
"""
Colors
"""
name = models.CharField(max_length=50, db_column="name", unique=True)
hex = models.CharField(max_length=6, db_column="hex", unique=True)
This model is foreignkey for some other model, so represented as dropdown list. I want to modify this list so it looks like
<select>
<option style="background-color:#hex1">name1</option>
<option style="background-color:#hex2">name2</option>
</select>
I know that django already does this, except the styling.
I also know that I need to extend select Widget and override render_option
method, but I don't know how to pass hex values to new widget.
How can I d this?
Thank you.