Reputation: 784
My env is: Django 2.0.6, Python 3.6.4
I have standard Django Admin (with inline edit):
How to add background color for each row in list view, when object has field is_active_city=True
? For example, background-color: green;
for is_active_city=True
, like this:
Upvotes: 2
Views: 2162
Reputation: 1131
There's a package django-liststyle
which may satisfy your need
Install it using pip install django-liststyle==0.2b
then in settings.py add 'liststyle'
to INSTALLED_APPS
list.
so now the admin.py for the relevant model would be
from liststyle import ListStyleAdminMixin
class CityAdmin(admin.ModelAdmin, ListStyleAdminMixin):
...
def get_row_css(self, obj, index):
if obj.is_active_city:
return 'green'
return 'red' # or any color for False
NOTE: If there are issues regarding future
package error, refer this link
Upvotes: 2