Search code examples
pythondjangodatabasedjango-modelsdjango-uploads

Django Is it efficient for DB to store uploaded files in model?


I have a form and if I store the file using form.save(), is the entire file content stored in DB or just the file path?

Suppose I have hundreds of thousands or millions of files. Is it efficient to store all of them in DB because size of the table must be huge?

If I don't want to store them in database and simple upload and keep them in local file system, is there any way I could get the list of all file names? By storing them in database, I simply get that by:

AllDocument.objects.all()

Thanks!


Solution

  • Actually, by default django stores only paths to files in db, not the files themselves, so there is no problem to store even millions of file entries. I do not think it is a good idea to store file paths somewhere else. At least, it will be more complex than using Django Manager.