File per folder limit - Django 1.7

Asked

Viewed 121 times

2

Does Django 1.7 provide any upload control mechanism per folder? I say this because when the number of files in a folder gets too large it tends to get slower.

An example would be: Every 800 files in a folder, a folder is created at the root of the uploads with a sequential number.

I hope that’s clear. Thank you.

  • In your controller check to create a new folder or not before saving the file.

1 answer

1

As far as I know, there is no control of this type, however there is a very simple way to prevent folders from growing too much: separating files by the date of upload, through FileField.upload_to:

class MeuModelo(models.Model):
    meu_campo = models.FileField(upload_to='pasta/%Y/%m/%d')

As an example, if you create an instance of this template on 05/14/2015 with the file teste.txt associated with the field meu_campo, and your MEDIA_ROOT for /var/www/uploads it will be saved in the file:

/var/www/uploads/pasta/2015/05/14/teste.txt

You can vary how to organize folders using the same parameters of strftime.

This does not guarantee, of course, that folders do not grow beyond a predefined size (will the user decided to register more than 800 files in the same day...), nor help anything if your application accepted upload files without them being associated with models. If this is a problem for you, just make this control by hand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.