views:

75

answers:

2

Is there a straightforward, common way to apply custom styling on admin change list element depending on its properties?

update

To be more precise: let's say I have a simple model object.

Foo

   field1
   field2
   field3

   @property
    property1()
   @property
    property2()

ModelAdmin.list_display is defined as a subset of the available fields, so not every attribute (field/property) is displayed in the change list table.

I'd like to apply custom CSS class to the object's row when certain condition is fulfilled, for example: if foo_instance.property1 is True then add class bar to the corresponding tr element.

A: 

Now copy the template admin/base_site.html from within the default Django admin template directory (django/contrib/admin/templates) into an admin subdirectory of whichever directory you're using in TEMPLATE_DIRS. For example, if your TEMPLATE_DIRS includes "/home/my_username/mytemplates", as above, then copy django/contrib/admin/templates/admin/base_site.html to /home/my_username/mytemplates/admin/base_site.html. Don't forget that admin subdirectory.

Note that any of Django's default admin templates can be overridden. To override a template, just do the same thing you did with base_site.html -- copy it from the default directory into your custom directory, and make changes.

from django's tutorial

Andrew Sledge
I know about overriding admin templates; the point is I see no way to do this without some deep hacking, since change list uses result_list inclusion tag which returns list o HTML objects (probably formset elements).
ohnoes
*depending on its properties* @ my question is the key problem here
ohnoes
A: 

What exactly do you mean by "change list element" and "it's properties"? Using CSS 2 or CSS 3 selectors you can do some things. Otherwise, you might be able to do it easily using jQuery (or whatever). Since it is merely presentation related, I think this would be the cleanest solution.

spookylukey
I've updated the question with some details.
ohnoes