2016-05-24 14 views
2

Wie ein ‚multiple‘ Attribut zur Eingabe in django Modelform hinzufügen, um dies zu erhalten:Wie füge ich ein 'multiple' Attribut zu inputtyp = 'file' in django modelForm hinzu?

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

Ist es möglich? Soll ich widget wie folgt verwenden:

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

Antwort

0

Versuchen Sie folgendes:

from django import forms 

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