2

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!

Paulo Pessoa
  • 2,509
  • 19
  • 30
hoan
  • 87
  • 1
  • 7
  • Have you read the docs for the Django [`FileField`](https://docs.djangoproject.com/en/1.8/ref/models/fields/#filefield)? – kylieCatt Sep 25 '15 at 02:48

3 Answers3

2

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.

chem1st
  • 1,624
  • 1
  • 16
  • 22
2

I think Djanga stores files in media or static root files, and the paths in the db.

xponent
  • 151
  • 2
  • 2
  • 10
0

Doc.

A local filesystem path that will be appended to your MEDIA_ROOT setting to determine the value of the url attribute.

I think this can help you, to clarify the question. A file-upload field . FileField

The file is saved as part of saving the model in the database, so the actual file name used on disk cannot be relied on until after the model has been saved.

FileField and FieldFile

Paulo Pessoa
  • 2,509
  • 19
  • 30