File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -212,9 +212,27 @@ def get_form_block(self):
212212 )
213213
214214
215+ class MultipleFileInput (forms .ClearableFileInput ):
216+ allow_multiple_selected = True
217+
218+
219+ class MultipleFileField (forms .FileField ):
220+ def __init__ (self , * args , ** kwargs ):
221+ kwargs .setdefault ("widget" , MultipleFileInput ())
222+ super ().__init__ (* args , ** kwargs )
223+
224+ def clean (self , data , initial = None ):
225+ single_file_clean = super ().clean
226+ if data and isinstance (data , (list , tuple )):
227+ result = [single_file_clean (d , initial ) for d in data ]
228+ else :
229+ result = single_file_clean (data , initial )
230+ return result
231+
232+
215233class MultiFileField (BaseField ):
216- field_class = forms . FileField
217- widget = forms . widgets . FileInput (attrs = {"multiple" : True })
234+ field_class = MultipleFileField
235+ widget = MultipleFileInput (attrs = {"multiple" : True })
218236 icon = "doc-full-inverse"
219237 label = _ ("Files field" )
220238
You can’t perform that action at this time.
0 commit comments