I have a file upload form which I can not get to validate successfully. The form loads fine and I can upload a file but after 'submit' I can not get past Fileform.is_valid() in the view. I have mostly copies this view and the model and form model from the Django 1.9 File Uploads documentation but I must be missing something.
The view.py is,
def file_sharing_form(request):
if request.method == "POST":
file = FileForm(request.POST, request.FILES)
if file.is_valid():
fform = file.save(commit=False)
fform.author = request.user
fform.pub_date = timezone.now()
fform.submitted_date = timezone.now()
fform.approved = False
fform.save()
# email admin
admin_email = User.objects.all().filter(is_superuser = True)
subject = 'File submitted to QQIresources, awaiting approval'
to_email = admin_email[0].email
from_email = request.user.email
message = 'A file has been submitted to QQIresources by ' + str(request.user) + ' and is awaiting admin approval. \n \n Title: ' + str(fform.title) + '\n Author: ' + str(fform.author) + '\n Description: ' + str(fform.description)
send_mail(subject, message, from_email, [to_email])
return redirect('init')
fileform = FileForm()
return render(request, 'file_form.html', {'fileform': fileform})