mailman_73
mailman_73

Reputation: 798

How to add a 'multiple' attribute to input type='file' in django modelForm?

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

Answers (1)

Casper Blake
Casper Blake

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

Related Questions