【发布时间】:2014-02-20 15:14:37
【问题描述】:
我有以下型号:
class InfoBox(models.Model):
type = models.ForeignKey(InfoBoxType)
content = models.TextField()
product = models.ForeignKey(Product)
我想为我的外键添加一个 CSS 类。我尝试了以下方法:
forms.py
class InfoBoxForm(ModelForm):
class Meta:
model = InfoBox
widgets = {
'type': ChoiceField(attrs={'class': 'hej'}),
}
我也试过了,但结果相同......
class InfoBoxForm(forms.Form):
type = forms.ChoiceField(
widget=forms.ChoiceField(attrs={'class':'special'}))
admin.py
class InfoBoxInline(admin.StackedInline):
model = InfoBox
extra = 0
form = InfoBoxForm
但我只得到这个:
__init__() got an unexpected keyword argument 'attrs'
我认为这很容易做到,那么我做错了什么......?
【问题讨论】: