如何在Django 1.1中自定义模型窗口小部件?

时间:2010-03-27 05:04:30

标签: python django django-forms

我正在尝试修改Django表单以使用textarea而不是我家表单中“地址”字段的正常输入。文档似乎意味着这从Django 1.1(我正在使用)变为1.2。但这两种方法都不适合我。这是我尝试过的:

class HouseForm(forms.ModelForm):
    address = forms.Textarea() # Should work with django 1.1, but doesn't

    class Meta:
        model = House
        #widgets = { 'address': forms.Textarea() } # 1.2 style - doesn't work either.

1 个答案:

答案 0 :(得分:4)

我认为需要将Textarea指定为小部件。

尝试

class HouseForm(forms.ModelForm):
    address = forms.CharField(widget=forms.Textarea)

    class Meta:
        model = House