I read in Django >= 1.6 docs:
"The field names in list_display will also appear as CSS classes in the HTML output, in the form of column- on each element. This can be used to set column widths in a CSS file."
OK. But, how?
class bollaAdmin(admin.ModelAdmin):
ordering = ['num']
list_display = ('num|width=15', 'Vendemmia','Cultivar', 'Provenienza' , 'netto', 'grado','montegradi')
Here's a snippet of HTML for the column containing the attribute headline from one of my admins:
<th scope="col" class="sortable column-headline">
<div class="text"><a href="?o=2.4.-5">Headline</a></div>
<div class="clear"></div>
</th>
You could set the width of that in CSS like this:
th.column-headline {
width: 10000000px;
}
Here's the lazy person's method to extend a column width in the django admin without doing a css override.
from django.utils.html import format_html
class MyModelAdmin(admin.ModelAdmin):
...
def get_column_extended_field(self, obj):
result = ''
field_value = obj.field_value
if field_value:
spaces = ' ' * 75
result = format_html('{result}<br/>' + spaces, result=field_value)
return result
get_column_extended_field.short_description = _('Extended Field')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With