Django's background color conditional fill admin

0

I'm wanting to coloris an entire row of a table, if its column in that row has some text, there are three possible situations: 1. the text itself, 2. fields with a "-", 3. fields with nothing. The reference column is a 9, field observation, and I tried the following unsuccessful way:

(function($) {
$(document).ready(function() {
$('#result_list tr:nth-child(9)').each(function() {
if ($(this).text() != '-') {
  $(this).css({
      "background-color": 'yellow',
      "color" : "black"
  });
}
if ($(this).text() != '') {
 $(this).css({
     "background-color": 'yellow',
      "color" : "black"
  });
}

});
});
})(django.jQuery);
    
asked by anonymous 21.02.2018 / 14:50

1 answer

0

Here's what I just tested in the Django 2.0.x admin from the Chrome console.

Rather, for every column in a field, Django adds a class in field-nomedocampo format. This should render in html:

<td class="field-campo">texto</td>

So, on the face of it, I think your jquery might be something like:

var $ = django.jQuery; // precisei disso para testar a solução
$('#result_list .field-SEU_CAMPO_AQUI').each(function() {
    if ($(this).text() == "-") {
        $(this).closest('tr').css("background-color", "red");
    }
});

I hope it's useful.

    
27.03.2018 / 18:50