如何添加多个'属性输入类型='文件'在django modelForm?

时间:2016-05-24 16:53:20

标签: python django django-forms

如何添加多个'在django ModelForm中输入的属性来获取:

<input id="id_photo_path" name="photo_path" type="file" multiple />.

有可能吗?我应该像这样使用widget

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ('text',)
        widgets = {
            'text': forms.Textarea(attrs={'class': 'form-control', 'rows': 3 }),
        }

1 个答案:

答案 0 :(得分:1)

试试这个:

from django import forms

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = {'photo_path',}
        widgets = {
            'photo_path': forms.ClearableFileInput(attrs={'multiple': True}),
        }