The syntax to add it in Model is:
class MyModel(models.Model): video = FileField(upload_to=None[, max_length=100, **options])
Here upload_to is local filesystem path that will be appended to your MEDIA_ROOT setting to determine the value of the url(mymodel.video.url) attribute.
Setting MEDIA_ROOT and upload_to
If,
MEDIA_ROOT = ‘/home/myname/files/
upload_to=’videos’
file: abc.flv
results in: /home/myname/files/videos/abc.flv
where as if,
MEDIA_ROOT = '/home/myname/files/'
upload_to='/videos'
and file : abc.flv
result will be saved in : '/videos/abc.flv' (i.e., root directory of filesystem)
You can also set upload_to='videos/%Y/%m/%d'. The '%Y/%m/%d' part of upload_to is strftime formatting; '%Y' is the four-digit year, '%m' is the two-digit month and '%d' is the two-digit day. If you upload a file on Jan. 15, 2007, it will be saved in the directory /home/myname/files/videos/2007/01/15.
Now here's how would you save the actual data.
from django.core.files.base import ContentFile def save_file(request): mymodel = MyModel.objects.get(id=1) file_content = ContentFile(request.FILES['video'].read()) mymodel.video.save(request.FILES['video'].name, file_content)
Hope the code is self explanatory. For further help do drop comment.


thanks!
How do you resolve problem with 1 user adding a big video file, and second one want to visit your site.
My prolem is that when I’m uploading a file, the rest of the system is down, and none can use it.
Is the explicit set of the file necessary? I think that if you have a MyModelForm and do
model = MyModelForm(request.POST, request.FILES) thats all you need
Exist some way, how to resolve this with chunks instead of read ?
Thanks !
It was very useful for me since a :
mymodel.video.write(f.read())
didn’t worked anymore with Django 1.1…
It’s a shame that the ContentFile object is not really documented from the Django FileField methods and related objects such as UploadedFile and so on (http://docs.djangoproject.com/en/dev/topics/http/file-uploads/)
Thanks for text very good