mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 01:36:33 +03:00
fixed multiple file upload
This commit is contained in:
parent
ff080e3354
commit
3f0da7b961
18
akarpov/common/forms.py
Normal file
18
akarpov/common/forms.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django import forms
|
||||
|
||||
class MultipleFileInput(forms.ClearableFileInput):
|
||||
allow_multiple_selected = True
|
||||
|
||||
|
||||
class MultipleFileField(forms.FileField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault("widget", MultipleFileInput())
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def clean(self, data, initial=None):
|
||||
single_file_clean = super().clean
|
||||
if isinstance(data, (list, tuple)):
|
||||
result = [single_file_clean(d, initial) for d in data]
|
||||
else:
|
||||
result = single_file_clean(data, initial)
|
||||
return result
|
|
@ -1,9 +1,12 @@
|
|||
from django import forms
|
||||
|
||||
from akarpov.common.forms import MultipleFileField
|
||||
|
||||
|
||||
class TracksLoadForm(forms.Form):
|
||||
address = forms.CharField(max_length=500)
|
||||
|
||||
|
||||
|
||||
class FileUploadForm(forms.Form):
|
||||
file = forms.FileField(widget=forms.ClearableFileInput(attrs={"multiple": True}))
|
||||
file = MultipleFileField()
|
||||
|
|
Loading…
Reference in New Issue
Block a user