How can i increase the width of filter_horizontal

2019-08-29 07:38发布

问题:

I am using django admin functionality.But in "Change user" section where we assign permissions for particular user i see select multiple widget.The width of this widget is not enough for me,i need to increase the width of the widget or add a horizontal scroll bar to it.How can i do this?

回答1:

It could be done in css e.g. with a custom css file override the following 3 classes.

.selector {
    width: 780px;
    float: left;
}

.selector select {
    width: 370px;
    height: 17.2em;
}

.selector-available, .selector-chosen {
    float: left;
    width: 370px;
    text-align: center;
    margin-bottom: 5px;
}


回答2:

I had to do this to make it work.

# admin.py
from django.contrib.auth.admin import GroupAdmin
from django.contrib.auth.models import Group

class CustomGroupAdmin(GroupAdmin):

    class Media:

        css = {
            'all': ('admin/css/permissions.css',)

        }

admin.site.unregister(Group)
admin.site.register(Group, CustomGroupAdmin)

and finally CSS file in admin/css/permissions.css

.selector {
    width: 1200px;
    float: left;
}

.selector select {
    width: 550px;
    height: 17.2em;
}

.selector-available, .selector-chosen {
    float: left;
    width: 550px;
    text-align: center;
    margin-bottom: 5px;
}


回答3:

"Kron" I understand that we can add class media to our classes in admin.py file.BUT i do not have any models defined that uses filter_horizontal widget.

But the admin application has already models defined "users" and "groups" that uses filter_horizontal widget.I need to change the width of that widget. so my problem is that i don't know in which class should i add class Meta with css.