Federico Aguirre
Federico Aguirre

Reputation: 316

How to change background row color in Django Admin NOT DUPLICATED

I have a simple model that I list in the admin, there is a field: etapa which takes a couple of values: {1, 3, 4, 5, 50, 77}.

I want to mark all etapa=50 rows in color RED.

This is not duplicated because I don't want to remark the text like in the posible "duplicated". I just want to fill the row background color.

models.py

class Registro(models.Model):
    ensayo = models.ForeignKey(Ensayo)
    fecha = models.DateTimeField(blank=False)
    fecha.date_fileter = True
    presion = models.FloatField(blank=False, help_text="Presion", verbose_name="PRESION (Bar)", null=False)
    etapa = models.IntegerField(blank=False, help_text="Etapa", null=False)
    tempin = models.FloatField(blank=False, help_text="Temp IN", verbose_name="TEMP. IN (C)", null=False)
    libre1 = models.FloatField(blank=False, help_text="Libre 1", null=False)
    libre2 = models.FloatField(blank=False, help_text="libre 2", null=False)
    libre3 = models.FloatField(blank=False, help_text="libre 3", null=False)

    def __unicode__(self):
        return "%s" % self.fecha

    class Meta:
        verbose_name_plural = "Registros"

I have a custom change_list.html

Any idea?

Upvotes: 0

Views: 1096

Answers (1)

Federico Aguirre
Federico Aguirre

Reputation: 316

I've finally solve this using the same template with jinja and if statment, asking about my value and set in the TR the background color:

change_list.html (part of, where I iterate over the result_list)

{% for row in cl.result_list %}
<tr class="{% cycle 'row1' 'row2' %}" {% if row.etapa == 50 %} style='background-color:#ffcccc' {% endif %} in>
    <td> {{ row.fecha }} </td>
    <td> {{ row.etapa }} </td>
    <td> {{ row.presion }} </td>
    <td> {{ row.tempin }} </td>
    <td>
</tr>{% endfor %}

Thanks, Fede

Upvotes: 1

Related Questions