Reputation: 798
How to add a 'multiple' attribute to input in django ModelForm to get this:
<input id="id_photo_path" name="photo_path" type="file" multiple />.
Is it possible? Should I use widget
like this:
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('text',)
widgets = {
'text': forms.Textarea(attrs={'class': 'form-control', 'rows': 3 }),
}
Upvotes: 2
Views: 1834
Reputation: 31
Try this:
from django import forms
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = {'photo_path',}
widgets = {
'photo_path': forms.ClearableFileInput(attrs={'multiple': True}),
}
Upvotes: 3