I'm using an Ajax code for uploading files. Django takes good care of file uploads on ModelForms. Just writing form.save() would upload any file data in the header, manage creating the folders if needed and even rename the file if a duplicate already exists. Take this ModelForm which only has one filed named file for example:
class UploadFileForm(ModelForm):
class Meta:
model = MyModel
fields = ('file',)
Since I'm using Ajax the only information I have in my view is request.FILES['file']. This is what I tried in my view:
form = UploadFileForm(initial={'file':request.FILES['file']})
if form.is_valid():
form.save()
But it returns an invalid form (file is required). I can do this using pure Python but with the power of Django where's the point in that?