gpt4 book ai didi

python - 在 django admin 中更改外键小部件的大小

转载 作者:行者123 更新时间:2023-11-28 22:56:32 26 4
gpt4 key购买 nike

过去两天我一直在尝试这样做,但我无法弄清楚。我正在使用 grappelli,并且尝试了几种方法。

我尝试指定小部件:

class MyForm(ModelForm):
class Meta:
model = MyModel
widgets = {
'foreign_key': widgets.TextInput(attrs={'width': '200'}),
}

在这种情况下,它似乎被忽略了。

我还尝试使用 Media 定义添加 css。这已加载,但在我的浏览器中检查该元素显示它已被 grappelli CSS 覆盖。

有没有我错过的简单方法?

最佳答案

我会重新尝试使用媒体定义添加 css,但这次,将 !important 放入您的 css 属性。

.widget input {
width: 200px !important;
}

来自 http://en.wikibooks.org/wiki/Cascading_Style_Sheets/Important

The important keyword makes a declaration take precedence over normal declarations—those that are not tagged with the important keyword. So "p { color: red ! important }" takes precedence over "p { color: green }".

关于python - 在 django admin 中更改外键小部件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15450079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com