6
我sooo關閉...但我不完全看到從上傳視圖到模型的連接。當我在模型的FileField
中使用回調時,上傳工作正常,但是我不確定實際文件副本的發生位置。目標是確保chunking
正在發生,但文件複製操作似乎隱藏在某處?Django文件上傳和型號FileField
這是我有:
型號:
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))
你看過http://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs#handling-uploaded-files?這似乎是你在找什麼。不想回答,因爲不知道你實際上在問什麼。 – Bartek 2010-07-05 20:07:25