添加list_filter时,如何修改/设置django modeladmin更改列表中的列宽? [英] How to fix/set column width in a django modeladmin change list table when a list_filter is added?

查看:471
本文介绍了添加list_filter时,如何修改/设置django modeladmin更改列表中的列宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力改进django项目中的admin.py,虽然我没有完全看到table_diplay中的三个字段的表格如何出现,但至少它比只获取一个默认对象更好列表中有一列跨越整个页面...



无论如何,我问的是为什么如果这样:



pre> class FieldAdmin(admin.ModelAdmin):
list_display =('name','label','standard',)

如下所示:





当我添加一个list_filter,像这样:



pre> class FieldAdmin(admin.ModelAdmin):
list_display =('name','label','standard',)
list_filter = ['standard' ,]

为什么看起来像这样?





有没有方式让列重新成长,以填补宽度,就像添加过滤器一样?我一直在阅读文档和谷歌搜索,但它似乎没有内置?我正在使用的项目目前正在使用django 1,2,3,final。



FWIW,导致这种情况的css在这里:

  .change-list .filtered表,.change-list .filtered .paginator,
.filtered #toolbar,.filtered div.xfull {
margin-right:160px!important;
width:auto!important;
}

禁用宽度样式规范修复它,但我宁愿做事情django方式如果有一个 - 我希望也许有一种方法来定制FieldAdmin类的过滤器视图?

解决方案

你可能需要参考: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template



基本上,change_list.html需要被覆盖。



你可以这样做:

  templates / 
admin /
app /
change_list.html

您可以获得copy_list.html的副本从 django / contrib / admin / templates / admin /



,并以css的方式更新你的愿望


I'm working on improving the admin.py in a django project, and while I'm not totally jazzed about how the table was coming out with three fields in the list_diplay, at least it's better than just getting a default object list with one column spanning the whole page...

Anyway, what I'm asking is why if this:

class FieldAdmin(admin.ModelAdmin):
    list_display = ('name', 'label', 'standard',  )

looks like this:

When I add a list_filter, like this:

class FieldAdmin(admin.ModelAdmin):
    list_display = ('name', 'label', 'standard',  )
    list_filter = ['standard',]

Why does it look like this?

Is there a way to get the columns to re-grow to fill the width like it was prior to adding the filter? I've been reading the docs and googling, but it doesn't seem built in? The project I'm working on is currently using django 1,2,3,final.

FWIW, the css that causes this is here:

.change-list .filtered table, .change-list .filtered .paginator, 
.filtered #toolbar, .filtered div.xfull {
    margin-right: 160px !important;
    width: auto !important;
}

disabling the width style specification fixes it, but I'd rather do things the django way if there is one - I was hoping maybe there's a way to customize the filter view from the FieldAdmin class?

解决方案

You may want to refer to this: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template

basically, the change_list.html needs to be overridden .

you can do it this way:

templates/
  admin/
    app/
      change_list.html

you can obtain a copy of change_list.html from django/contrib/admin/templates/admin/

and update the css the way you desire.

这篇关于添加list_filter时,如何修改/设置django modeladmin更改列表中的列宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆