Example model:
class Article(models.Model):
is_published = models.BooleanField(default=False)
Is there an easy way to add "is_published" css class to all in Django admin list view to all rows displaying objects with is_published==True?
I'm not quite sure is it what you looking for. The following example displays all "is_published" fields in red font, where "is_published==True"
class Article(models.Model):
is_published = models.BooleanField(default=False)
def colored_is_published(self):
if self.is_published:
cell_html = '<span style="color: red;">%s</span>'
else:
cell_html = '<span>%s</span>'
# for below line, you may consider using 'format_html', instead of python's string formatting
return cell_html % self.is_published
colored_is_published.allow_tags = True
class ArticleAdmin(admin.ModelAdmin):
list_display = (......, 'colored_is_published')
Reference: Django list display
class Mediato add custom js & css for theModelAdminclass.