Files limit per folder - Django 1.7

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 slow down.

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

I hope it has become clear. Thank you.

    
asked by anonymous 27.03.2015 / 11:33

1 answer

1

As far as I know, there is no such control, however there is a very simple way to prevent folders from overgrowing: separating files by upload with FileField.upload_to :

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

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

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

You can vary how you organize your folders by using the same strftime .

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

    
14.04.2015 / 08:34