1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from django.newforms.widgets import Input
class MultiFileInput(Input):
input_type = 'file'
needs_multipart_form = True
def render(self, name, value, attrs=None):
if attrs is None:
attrs = {}
if attrs.has_key('class'):
attrs['class'] += ' multi'
else:
attrs['class'] = 'multi'
name += '[]'
return super(MultiFileInput, self).render(name, None, attrs=attrs)
def value_from_datadict(self, data, files, name):
"File widgets take data from FILES, not POST"
return files.get(name, None)
|
More like this
- Admin Image Widget by baumer1122 3 years, 9 months ago
- Feet and Inches FormField/Widget by btaylordesign 1 year, 4 months ago
- Multiple Select Widget with jQueryUI by maguspk 1 year, 11 months ago
- MultiSelect checkbox iterator template filter by ke1g 1 year, 9 months ago
- upload handler decorators by Rozza 3 years, 10 months ago
Comments
Nice and useful widget, just what I was going to write myself. You saved me the trouble!
Why do you append "[]" to the end of the name though?
#
Hi! I'm new to django, can you tell me how to use this snippet? I tried creating new form with MultiFileInput as a field but everytime I get error that no files were uploaded..
#