9
我伸出UserCreationForm 並增加Charfield上升幅度
username=forms.CharField(max_length=30,widget=forms.TextInput(attrs={'size':'80'}))
但用戶名字段寬度保持不變。如何增加它?
我伸出UserCreationForm 並增加Charfield上升幅度
username=forms.CharField(max_length=30,widget=forms.TextInput(attrs={'size':'80'}))
但用戶名字段寬度保持不變。如何增加它?
嘗試在形式指定窗口小部件,如下面的例子:
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.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'})}
}
因此,關於問題中的代碼:基本上只是刪除'80'上的引號? – guival 2016-07-19 14:11:26