I am trying to resize many django 1.8 admin fields.
models.py
from django.db import models class Material(models.Model): type = models.CharField(max_length=20, primary_key=True) def __unicode__(self): return self.type class Pen(models.Model): label = models.CharField(max_length=20, blank=True, default='') materials = models.ManyToManyField(Material)
admin.py
from django.contrib import admin from django.conf.urls import url from .models import * from django.forms import SelectMultiple @admin.register(Pen) class PenAdmin(admin.ModelAdmin): filter_horizontal = ('materials',)
resize_fields.js
document.onload = function() { document.getElementById("id_materials_to").style.width="70px"; };
As you can see, I tried 3 approaches:
1: using formfield_overrides. It didn't make any difference.
2: loading javascript to resize the html object. It launches, but does not change its size, since the script seems to run before the widget loads.
3: using get_form. As shown below, it only resizes one of the selection fields.

Does anyone know how to resize horizontally?
UPDATE: I found that:
class PenAdmin(admin.ModelAdmin): formfield_overrides = { models.ManyToManyField: {'widget': SelectMultiple(attrs={'size':'5', 'style': 'color:blue;width:250px'})}, }
will work since I deleted filter_horizontal, but I want to use filter_horizontal! If I'm not mistaken, the filter_horizontal parameter will use a MultiWidget, which apparently does not pass override attributes for the sub-sections. However, I think there should be a solution where I can run javascript after the page loads. Help plz