summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/howto/custom-file-storage.txt20
-rw-r--r--docs/ref/contrib/staticfiles.txt1
-rw-r--r--docs/ref/files/storage.txt6
-rw-r--r--docs/ref/settings.txt38
-rw-r--r--docs/releases/4.2.txt6
-rw-r--r--docs/topics/files.txt12
-rw-r--r--docs/topics/testing/tools.txt19
7 files changed, 93 insertions, 9 deletions
diff --git a/docs/howto/custom-file-storage.txt b/docs/howto/custom-file-storage.txt
index 9974c30452..47abe3e7fd 100644
--- a/docs/howto/custom-file-storage.txt
+++ b/docs/howto/custom-file-storage.txt
@@ -116,3 +116,23 @@ free unique filename cannot be found, a :exc:`SuspiciousFileOperation
If a file with ``name`` already exists, ``get_alternative_name()`` is called to
obtain an alternative name.
+
+.. _using-custom-storage-engine:
+
+Use your custom storage engine
+==============================
+
+.. versionadded:: 4.2
+
+The first step to using your custom storage with Django is to tell Django about
+the file storage backend you'll be using. This is done using the
+:setting:`STORAGES` setting. This setting maps storage aliases, which are a way
+to refer to a specific storage throughout Django, to a dictionary of settings
+for that specific storage backend. The settings in the inner dictionaries are
+described fully in the :setting:`STORAGES` documentation.
+
+Storages are then accessed by alias from from the
+:data:`django.core.files.storage.storages` dictionary::
+
+ from django.core.files.storage import storages
+ example_storage = storages["example"]
diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt
index 7ca3584c33..08fc23bdb1 100644
--- a/docs/ref/contrib/staticfiles.txt
+++ b/docs/ref/contrib/staticfiles.txt
@@ -23,6 +23,7 @@ Settings
See :ref:`staticfiles settings <settings-staticfiles>` for details on the
following settings:
+* :setting:`STORAGES`
* :setting:`STATIC_ROOT`
* :setting:`STATIC_URL`
* :setting:`STATICFILES_DIRS`
diff --git a/docs/ref/files/storage.txt b/docs/ref/files/storage.txt
index fa79a4f91a..d5daccf834 100644
--- a/docs/ref/files/storage.txt
+++ b/docs/ref/files/storage.txt
@@ -9,6 +9,12 @@ Getting the default storage class
Django provides convenient ways to access the default storage class:
+.. data:: storages
+
+ .. versionadded:: 4.2
+
+ Storage instances as defined by :setting:`STORAGES`.
+
.. class:: DefaultStorage
:class:`~django.core.files.storage.DefaultStorage` provides
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
index b1a8e2444d..d1b638f4b6 100644
--- a/docs/ref/settings.txt
+++ b/docs/ref/settings.txt
@@ -2606,6 +2606,43 @@ Silenced checks will not be output to the console.
See also the :doc:`/ref/checks` documentation.
+.. setting:: STORAGES
+
+``STORAGES``
+------------
+
+.. versionadded:: 4.2
+
+Default::
+
+ {}
+
+A dictionary containing the settings for all storages to be used with Django.
+It is a nested dictionary whose contents map a storage alias to a dictionary
+containing the options for an individual storage.
+
+Storages can have any alias you choose.
+
+The following is an example ``settings.py`` snippet defining a custom file
+storage called ``example``::
+
+ STORAGES = {
+ # ...
+ "example": {
+ "BACKEND": "django.core.files.storage.FileSystemStorage",
+ "OPTIONS": {
+ "location": "/example",
+ "base_url": "/example/",
+ },
+ },
+ }
+
+``OPTIONS`` are passed to the ``BACKEND`` on initialization in ``**kwargs``.
+
+A ready-to-use instance of the storage backends can be retrieved from
+:data:`django.core.files.storage.storages`. Use a key corresponding to the
+backend definition in :setting:`STORAGES`.
+
.. setting:: TEMPLATES
``TEMPLATES``
@@ -3663,6 +3700,7 @@ File uploads
* :setting:`FILE_UPLOAD_TEMP_DIR`
* :setting:`MEDIA_ROOT`
* :setting:`MEDIA_URL`
+* :setting:`STORAGES`
Forms
-----
diff --git a/docs/releases/4.2.txt b/docs/releases/4.2.txt
index aa2deed932..ecc9a06a87 100644
--- a/docs/releases/4.2.txt
+++ b/docs/releases/4.2.txt
@@ -91,6 +91,12 @@ In-memory file storage
The new ``django.core.files.storage.InMemoryStorage`` class provides a
non-persistent storage useful for speeding up tests by avoiding disk access.
+Custom file storages
+--------------------
+
+The new :setting:`STORAGES` setting allows configuring multiple custom file
+storage backends.
+
Minor features
--------------
diff --git a/docs/topics/files.txt b/docs/topics/files.txt
index 6f7f9c21e2..eb4e655cfa 100644
--- a/docs/topics/files.txt
+++ b/docs/topics/files.txt
@@ -239,3 +239,15 @@ For example::
class MyModel(models.Model):
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::
+
+ from django.core.files.storage import storages
+
+ class MyModel(models.Model):
+ upload = models.FileField(storage=lambda: storages["custom_storage"])
+
+.. versionchanged:: 4.2
+
+ Support for ``storages`` was added.
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 139d66e64b..524fc85584 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -1441,15 +1441,16 @@ when settings are changed.
Django itself uses this signal to reset various data:
-================================ ========================
-Overridden settings Data reset
-================================ ========================
-USE_TZ, TIME_ZONE Databases timezone
-TEMPLATES Template engines
-SERIALIZATION_MODULES Serializers cache
-LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
-MEDIA_ROOT, DEFAULT_FILE_STORAGE Default file storage
-================================ ========================
+================================= ========================
+Overridden settings Data reset
+================================= ========================
+USE_TZ, TIME_ZONE Databases timezone
+TEMPLATES Template engines
+SERIALIZATION_MODULES Serializers cache
+LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
+MEDIA_ROOT, DEFAULT_FILE_STORAGE Default file storage
+STATIC_ROOT, STATIC_URL, STORAGES Storages configuration
+================================= ========================
Isolating apps
--------------