Reputation: 16610
This is the first time I've tried to upload a file with Django. I did something and it worked, though I realized later that it's not the correct way to do it. When I called save on the object, did it call a built-in handler for the FileField? I realize that I should create my own handler but I was just curious why this worked.
def upload_test(request):
user=User.objects.get(pk=user.id)
photoform=PhotoForm()
if request.method=='POST':
photoform=Post_PhotoForm(request.POST,request.FILES)
if photoform.is_valid():
photo=photoform.save(commit=False)
photo.user=user
photo.save()
return HttpResponse('success')
else:
return HttpResponse('%s' %photoform.errors)
return render_to_response("site/upload_test.html", {'photoform':photoform}, context_instance=RequestContext(request))
This is saving the object and uploading the file to the directory specified in the FileField.
If I create a handler which writes the file in chunks, how can I also save the photoform instance? Will it create duplicates?
Thanks for the insight.
Upvotes: 2
Views: 314