我正在扩展UserCreationForm
并添加了
username=forms.CharField(max_length=30, widget=forms.TextInput(attrs={'size':'80'}))
但用户名字段宽度不会更改。我怎样才能增加它?
答案 0 :(得分:13)
尝试在表单中指定小部件,如下例所示:
<强> models.py 强>
class Photo(models.Model):
caption = models.CharField(max_length=80)
<强> admin.py 强>
class PhotoAdmin(admin.ModelAdmin):
list_display = (u'preview', u'caption')
search_fields = (u'caption')
form = forms.PhotoAdminForm
<强> forms.py 强>
class PhotoAdminForm(forms.ModelForm):
class Meta:
widgets = { 'caption': forms.TextInput(attrs={'size': 80})}
作为替代方案,您可以使用以下内容:
<强> forms.py 强>
class PhotoAdminForm(forms.ModelForm):
caption = forms.CharField(widget=forms.TextInput(attrs={'size':80}))
答案 1 :(得分:1)
从1.7开始你可以这样解决:
<强> admin.py 强>
class PhotoAdmin(admin.ModelAdmin):
list_display = (u'preview', u'caption')
search_fields = (u'caption')
formfield_overrides = {
models.CharField: {'widget': TextInput(attrs={'size': '80'})}
}