我离成功很近了……但我还没有完全理解上传视图与模型之间的联系。当我在模型的
以下是我的代码: 模型:
FileField
中使用回调时,上传可以正常工作,但是我不确定实际的文件复制发生在哪里。目标是确保chunking
正在进行,但是文件复制操作似乎被隐藏在某个地方?以下是我的代码: 模型:
def get_media_upload_dir(instance, filename):
user_id = instance.user.id
upload_dir = "%s/%d/%s" % (settings.MEDIA_ROOT, user_id, filename)
print "Upload dir set to: %s" % upload_dir
return upload_dir
class MediaFile(models.Model):
media_file = models.FileField(upload_to=get_media_upload_dir)
download_count = models.PositiveIntegerField(default=0)
视图:
def file_upload(request, course_id):
if request.method == 'POST':
form = FileUploadForm(request.POST, request.FILES)
if form.is_valid():
uploaded = form.cleaned_data['file_upload']
mediaFile = MediaFile(media_file=uploaded,
owner=request.user.profile,
creator=request.user.profile)
mediaFile.save()
return HttpResponseRedirect('/course/%s/' % course_id)
else:
form = FileUploadForm()
return render_to_response('course/file_upload.html', {'form':form,'course':course}, context_instance=RequestContext(request))