Created
August 30, 2012 18:26
-
-
Save ptgolden/3536676 to your computer and use it in GitHub Desktop.
Multiple file input field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultipleFileInputWidget(forms.FileInput): | |
input_type = 'file' | |
def render(self, name, value, attrs=None): | |
attrs = attrs if attrs else {} | |
attrs['multiple'] = 'multiple' | |
return super(MultipleFileInputWidget, self).render(name, value, attrs=attrs) | |
def value_from_datadict(self, data, files, name): | |
return files.getlist(name, None) | |
class MultipleImageInputField(forms.ImageField): | |
widget = MultipleFileInputWidget | |
def to_python(self, data): | |
# Call Image Field validation for each file | |
return list(super(MultipleImageInputField, self).to_python(img) for img in data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment