The Django Djitney - enhance the app task | changing the color of the subway line

Hello,

I have a question about the extra task in The Django Djitney mini-project:

  • Add a color field to lines, like you may have seen on your local public transportation lines. Update the templates so that the text of each line in the Lines table is colored according to the line’s color.

I can’t figure out how to solve it. So far I’ve added a color field to the class Line so you can select it for the line.

class Line(models.Model):
  LINE_COLOR_CHOICES = [
        ('R','Red'),
        ('B','Blue'),
        ('Y','Yellow'),
        ('W','White'),
        ('B','Black'),
        ('G','Green'),
    ]
  name = models.CharField(unique=True, max_length=200)
  color = models.CharField(max_length=20, choices=LINE_COLOR_CHOICES, default='B')

Next, I was thinking about add on the top to home.html

<style>
    .line-table li{
      background: {{ line.color }};
    }
</style>

but this didn’t work. Someone can give me a tip or some suggestion how to make it in proper way :slight_smile:

ok, I just figured out how to do this.
need to change the first letters of color on full name

class Line(models.Model):
  LINE_COLOR_CHOICES = [
        ('red','Red'),
        ('blue,'Blue'),
        ('yellow','Yellow'),
        ('white','White'),
        ('black','Black'),
        ('green','Green'),
    ]
  name = models.CharField(unique=True, max_length=200)
  color = models.CharField(max_length=20, choices=LINE_COLOR_CHOICES, default='blue')

and put inside one of

<td style="color: {{ line.color }}"`>