4

I am trying to make some CSS customizations on the Change List in Django´s Admin. More specifically on the table results.

I am trying to add some CSS and markup to the tds of the table.

The problem is that that portion of code is hidden inside of the template tags (django/contrib/admin/templatetags/admin_list.py) and not in the template itself (/templates/admin/change_list_results.html)

I was able to overwrite the template and make some of the changes but I really need to know how can I "inherit" template tags to my project directory instead of applying changes directly to Django's template tag directory.

I tried following these suggestions but none of them worked at least for me.

Extending Django Admin Templates - altering change list

I identified that the changes need to be done inside of the items_for_result method inside of admin_list.py.

The thing is how is this overridden? items_for_result is an internal method and its not registered in the tags library so it's not callable from the template.

So: how do I overwrite it and tell Django not to use the old method but the one I indicate?

1 Answer 1

0

I'm afraid that this kind of change can not be done easily. To overwrite this method you would need to modify Django source code. It's not recommended though.

If it's only CSS/HTML change, you can do it by adding the style with JavaScript. There is a simple way to add the custom JS to the admin by creating custom form and adding new JS files to Meta class.

Have a look on the docs and example here.

1
  • Thanks Mr. Coffee, yes I've recently been working with forms and been writing my own widgets. This has solved my problem, although it would be nice to overwrite any Django class or method without overwriting the source code. Nov 24, 2015 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.