1
0
mirror of https://github.com/django/django.git synced 2025-02-28 11:34:28 +00:00

[4.2.x] Fixed #34530 -- Improved docs when customizing storage for FileField.

Backport of 506f93f0c37ed9c44069edeab8baa66da5f7e03a from main
This commit is contained in:
Ran Benita 2023-05-02 21:32:24 +03:00 committed by Natalia
parent f200d83698
commit 4c68482c3e

View File

@ -261,13 +261,17 @@ For example::
my_file = models.FileField(storage=select_storage)
In order to set a storage defined in the :setting:`STORAGES` setting you can
use a lambda function::
use :data:`~django.core.files.storage.storages`::
from django.core.files.storage import storages
def select_storage():
return storages["mystorage"]
class MyModel(models.Model):
upload = models.FileField(storage=lambda: storages["custom_storage"])
upload = models.FileField(storage=select_storage)
.. versionchanged:: 4.2