def handle_uploaded_file(f):
if f:
fl = '/tmp/%s' % f.name #или другой путь
destination = open(fl, 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()
return fl
else:
return False
def blah_blah(request):
....
for some_file in request.FILES.getlist('file'):
f = handle_uploaded_file(some_file)
или так сохранять:
for f in request.FILES.getlist('data'):
a = Attachment(data=f, ...)
a.save()
где Attachment что-то типа:
class Attachment(models.Model):
data = models.FileField(upload_to='uploads/%Y/%m/%d',)
post = models.ForeignKey(Post)
def __unicode__(self):
return self.data.name.split('/')[-1]
Updated 28 Nov. 2014, 16:49 by wdstrm.