Download Django and FileField Model Files

I'm sooo close ... but I don't quite understand the connection from the load view to the model. When I use the callback in the FileField model, the download is done, but I'm not sure where the actual copy of the file is going. The goal is to make sure chunking happening, but the file copy action seems to be hidden somewhere?

Here is what I have:

Model:

 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) 

View:

 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)) 
+6
python file django upload
source share
1 answer

Saving happens here: http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/files.py#L90 . Django uses its own API to access file storage: http://docs.djangoproject.com/en/dev/ref/files/storage/ . But if you need something you need, you can go with Bartek’s offer!

+1
source share

All Articles