Proposal: Add CSS classes to admin changelist rows

I’d like to propose adding custom HTML/CSS classes to the admin change list table row <tr> elements. That way the styling of each table row could vary based on the model data.

As a basic example, it could be useful to highlight specific table rows, for instance greying out inactive users or highlighting users with expired passwords in red.

Thoughts?

I have two initial reactions to this:

I agree with Ken that this is outside of the design goal of the admin.

Fair enough.

I’m still of the opinion that this is a minor cosmetic change that falls within the stated goals, especially the first paragraph. It’s definitely not a sufficiently complex feature to warrant ditching the admin in favor of custom views for projects that are already using it. But I will defer to your judgement.

Re implementation: I have already implemented this feature since I’ve been asked for it a couple of times. It’s a simple addition, but since it requires augmenting the results_list template tag so that the css classes are available in the template, I thought it might make a useful addition to the standard admin interface.

First, I apologize if I have given you, or anyone, the impression that I have “made a decision” regarding this issue (or any issue for that matter). As far as what happens within Django is concerned, my voice is just one among many. While I don’t personally think that this idea would get much traction, it’s just my opinion.

<conjecture>
Just tossing out ideas here, but I wouldn’t think that that would be necessary. I can see a couple of options here. You could override the ModelAdmin.get_changelist_instance method to attach the additional data to the ChangeList object before returning it to changelist_view. Or, you may be able to do this by overriding the ModelAdmin.get_changelist_formset method to attach the additional data there. Either way, the objective would be to alter the cl object being passed to TemplateResponse at the source so that the template has direct access to it.
</conjecture>

No need to apologize, I didn’t mean to suggest you had decided (perhaps I should have said ‘expertise’ rather than ‘judgement’?). My apologies for any misunderstanding as well - my meaning is simply that you (almost certainly) have a better idea than I do on whether this would be a sensible addition to the admin.

Interesting conjecture. ModelAdmin.get_changelist_instance could work without the need to modify the template tag. To be consistent with the current admin design a template tag is probably still the right place to do the field lookups, but I see no reason why the tag couldn’t be separate to results_list if the right data can be accessed in the ChangeList object. And in that case this feature could easily work as a standalone app. I will have a closer look at it shortly.