Skip to content

Commit 332706e

Browse files
author
James Brewer
committed
Fixed #23376 -- Made documentation about required Storage methods
consistent. The following methods **should** be implemented, but are not required: * Storage.delete() * Storage.exists() * Storage.listdir() * Storage.size() * Storage.url() Updated documentation to reflect this fact and give a couple of examples where some methods may not be implemented. Add a warning that not implementing some methods will result in a partial (possibly broken) interface. Ticket: https://code.djangoproject.com/ticket/23376
1 parent 6d0547c commit 332706e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/howto/custom-file-storage.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,28 @@ You'll need to follow these steps:
4141
``django.utils.deconstruct.deconstructible`` class decorator for this
4242
(that's what Django uses on FileSystemStorage).
4343

44-
Your custom storage system may override any of the storage methods explained in
45-
:doc:`/ref/files/storage`, but you **must** implement the following methods:
44+
By default, the following methods raise `NotImplementedError` and will
45+
typically have to be overridden:
4646

4747
* :meth:`Storage.delete`
4848
* :meth:`Storage.exists`
4949
* :meth:`Storage.listdir`
5050
* :meth:`Storage.size`
5151
* :meth:`Storage.url`
5252

53+
Note however that not all these methods are required and may be deliberately
54+
omitted. As it happens, it is possible to leave each method unimplemented and
55+
still have a working Storage.
56+
57+
By way of example, if listing the contents of certain storage backends turns
58+
out to be expensive, you might decide not to implement `Storage.listdir`.
59+
60+
Another example would be a backend that only handles writing to files. In this
61+
case, you would not need to implement any of the above methods.
62+
63+
Ultimately, which of these methods are implemented is up to you. Leaving some
64+
methods unimplemented will result in a partial (possibly broken) interface.
65+
5366
You'll also usually want to use hooks specifically designed for custom storage
5467
objects. These are:
5568

0 commit comments

Comments
 (0)