我正在努力改进一个 django 项目中的 admin.py,虽然我并不完全对 list_diplay 中包含三个字段的表的输出方式感到兴奋,但至少它比只获得一个默认对象要好一列跨越整个页面的列表...
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', )
看起来像这样:
当我添加一个 list_filter 时,像这样:
When I add a list_filter, like this:
class FieldAdmin(admin.ModelAdmin):
list_display = ('name', 'label', 'standard', )
list_filter = ['standard',]
为什么会这样?
有没有办法让列重新增长以填充宽度,就像添加过滤器之前一样?我一直在阅读文档和谷歌搜索,但它似乎没有内置?我正在做的项目目前使用的是django 1,2,3,final.
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,导致这种情况的 css 在这里:
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;
}
禁用宽度样式规范可以修复它,但如果有的话,我宁愿以 django 方式做事 - 我希望也许有一种方法可以从 FieldAdmin 类自定义过滤器视图?
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?
你可能想参考这个:https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-模板
基本上,change_list.html 需要被覆盖.
basically, the change_list.html needs to be overridden .
你可以这样做:
templates/
admin/
app/
change_list.html
您可以从 django/contrib/admin/templates/admin/
并按照您想要的方式更新 css.
and update the css the way you desire.
这篇关于添加 list_filter 时,如何在 django modeladmin 更改列表中修复/设置列宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!