Overriding admin css in django

rajan sthapit picture rajan sthapit · Sep 9, 2011 · Viewed 67.9k times · Source

I want to change certain css in admin django like base.css. Is it better to change directly in the django library? How can I override it in the best way?

Answer

Torsten Engelbrecht picture Torsten Engelbrecht · Sep 9, 2011

It depends a lot of what you want to do. Though first of all: do not overwrite it in the Django admin directly. You got two options I think are reasonable:

  1. If you want to change the appearance of the admin in general you should override admin templates. This is covered in details here: Overriding admin templates. Sometimes you can just extend the original admin file and then overwrite a block like {% block extrastyle %}{% endblock %} in django/contrib/admin/templates/admin/base.html as an example.
  2. If your style is model specific you can add additional styles via the Media meta class in your admin.py. See an example here:
class MyModelAdmin(admin.ModelAdmin):
    class Media:
        js = ('js/admin/my_own_admin.js',)    
        css = {
             'all': ('css/admin/my_own_admin.css',)
        }