Django 1.10: extend/override admin css
<p>I want to override the css definition of a select-multiple widget by decreasing the min-height attribute from <code>contrib/admin/static/admin/css/base.css</code>. However, my css is not loaded I think. I use a custom admin form and have defined the Media subclass within this form as well as within the corresponding ModelAdmin:</p>

<pre><code>    class Media:
        css = {
            'all': ('/css/admin widgets.css',)
        }
</code></pre>

<p>The file itself is located in <code>myapp/static/css/admin widgets.css</code> and contains:</p>

<pre><code>    select[multiple] {
        min-height: 65px;
    }
</code></pre>

<p>In <code>settings.py</code>, I have defined</p>

<pre><code>    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    STATICFILES_DIRS = [os.path.join(BASE_DIR, "myapp", "static")]
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    STATIC_URL = '/static'
</code></pre>

<p>I've ran <code>manage.py collectstatic</code> which collected all the admin files and my own css file in the project's static-subdir. I've also extended <code>urls.py</code> as described <a href="https://docs.djangoproject.com/en/1.10/howto/static-files/#serving-static-files-during-development" rel="nofollow">here</a>, but the widget is still rendered with 150px min-height which is defined in base.css. Any help is appreciated.</p>

<p><strong>EDIT:</strong> I actually use the form within a <code>django.contrib.admin.TabularInline</code>. I just also tried to add the Media-subclass to this inline - to no avail.</p>

<p>I've found the solution myself. It is indeed only one character, but not the whitespace in the filename that Jonas pointed me to (I'm on a Windows filesystem, maybe that's different on linux). Instead, it's the leading slash of the URL in the Media class. Instead of:</p>

<pre><code>    class Media:
        css = {
            'all': ('/css/admin widgets.css',)
        }    
</code></pre>

<p>it has to be</p>

<pre><code>    class Media:
        css = {
            'all': ('css/admin widgets.css',)
        }    
</code></pre>

<p>or otherwise Django looks directly in the project's root directory for <code>css/admin widgets.css</code> instead of the static subdirectory <code>static/css/admin.widgets.css</code>.</p>

<p>Furthermore, it seems irrelevant if the Media subclass resides in the Admin, the Inline or the Form directly. It works in any case.</p>

<p>And one more hint: <em>Always</em> clear the browser cache before testing when working with css or js. How many times have I already fallen into the same pit? -.-</p>

python css django admin