Charfield增加宽度 [英] Charfield increase width

查看:162
本文介绍了Charfield增加宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在扩展UserCreationForm
并添加了

I am extending UserCreationForm and have added

username=forms.CharField(max_length=30,widget=forms.TextInput(attrs={'size':'80'}))

但用户名字段宽度保持不变。如何增加?

but username field width remains unchanged. How to increase it ???

推荐答案

尝试在表单中指定小部件,如以下示例所示:

Try specifying widgets in the form, as in the following example:

models.py

class Photo(models.Model):
    caption = models.CharField(max_length=80)

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})}

另外,您可以使用以下内容:

As alternative, you can use the following:

forms.py

class PhotoAdminForm(forms.ModelForm):
    caption = forms.CharField(widget=forms.TextInput(attrs={'size':80}))

这篇关于Charfield增加宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆