Skip to content

Commit 25798c5

Browse files
committed
Use new STORAGES setting from Django 4.2+
1 parent c4cb715 commit 25798c5

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

docs/usage.md

+21-15
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ pip install django-minio-storage
66

77
Add `minio_storage` to `INSTALLED_APPS` in your project settings.
88

9-
The last step is setting `DEFAULT_FILE_STORAGE` to
10-
`"minio_storage.storage.MinioMediaStorage"`, and `STATICFILES_STORAGE` to
11-
`"minio_storage.storage.MinioStaticStorage"`.
9+
The last step is setting `STORAGES['default']['BACKEND']` to
10+
`'minio_storage.storage.MinioMediaStorage'`, and `STORAGES['staticfiles']['BACKEND']` to
11+
`'minio_storage.storage.MinioStaticStorage'`.
1212

1313
## Django settings Configuration
1414

@@ -18,7 +18,7 @@ The following settings are available:
1818
`minio.example.org:9000` (note that there is no scheme)).
1919

2020
- `MINIO_STORAGE_ACCESS_KEY` and `MINIO_STORAGE_SECRET_KEY` (mandatory)
21-
21+
2222
- `MINIO_STORAGE_REGION`: Allows you to specify the region. By setting this
2323
configuration option, an additional HTTP request to Minio for region checking
2424
can be prevented, resulting in improved performance and reduced latency for
@@ -34,18 +34,18 @@ The following settings are available:
3434
- `MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET`: whether to create the bucket if it
3535
does not already exist (default: `False`)
3636

37-
- `MINIO_STORAGE_ASSUME_MEDIA_BUCKET_EXISTS`: whether to ignore media bucket
38-
creation and policy.
37+
- `MINIO_STORAGE_ASSUME_MEDIA_BUCKET_EXISTS`: whether to ignore media bucket
38+
creation and policy.
3939
(default: `False`)
4040

4141
- `MINIO_STORAGE_AUTO_CREATE_MEDIA_POLICY`: sets the buckets public policy
4242
right after it's been created by `MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET`.
4343
Valid values are: `GET_ONLY`, `READ_ONLY`, `WRITE_ONLY`, `READ_WRITE` and
4444
`NONE`. (default: `GET_ONLY`)
45-
45+
4646
- `MINIO_STORAGE_MEDIA_OBJECT_METADATA`: set default additional metadata for
4747
every object persisted during save operations. The value is a dict with
48-
string keys and values, example: `{"Cache-Control": "max-age=1000"}`.
48+
string keys and values, example: `{'Cache-Control': 'max-age=1000'}`.
4949
(default: `None`)
5050

5151
- `MINIO_STORAGE_STATIC_BUCKET_NAME`: the bucket that will act as `STATIC`
@@ -55,18 +55,18 @@ The following settings are available:
5555
does not already exist (default: `False`)
5656

5757

58-
- `MINIO_STORAGE_ASSUME_STATIC_BUCKET_EXISTS`: whether to ignore the static bucket
59-
creation and policy.
58+
- `MINIO_STORAGE_ASSUME_STATIC_BUCKET_EXISTS`: whether to ignore the static bucket
59+
creation and policy.
6060
(default: `False`)
6161

6262
- `MINIO_STORAGE_AUTO_CREATE_STATIC_POLICY`: sets the buckets public policy
6363
right after it's been created by `MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET`.
6464
Valid values are: `GET_ONLY`, `READ_ONLY`, `WRITE_ONLY`, `READ_WRITE` and
6565
`NONE`. (default: `GET_ONLY`)
66-
66+
6767
- `MINIO_STORAGE_STATIC_OBJECT_METADATA`: set default additional metadata for
6868
every object persisted during save operations. The value is a dict with
69-
string keys and values, example: `{"Cache-Control": "max-age=1000"}`.
69+
string keys and values, example: `{'Cache-Control': 'max-age=1000'}`.
7070
(default: `None`)
7171

7272
- `MINIO_STORAGE_MEDIA_URL`: the base URL for generating urls to objects from
@@ -110,13 +110,19 @@ The following settings are available:
110110
STATIC_URL = '/static/'
111111
STATIC_ROOT = './static_files/'
112112

113-
DEFAULT_FILE_STORAGE = "minio_storage.storage.MinioMediaStorage"
114-
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
113+
STORAGES = {
114+
'default': {
115+
'BACKEND': 'minio_storage.storage.MinioMediaStorage',
116+
},
117+
'staticfiles': {
118+
'BACKEND': 'minio_storage.storage.MinioStaticStorage',
119+
},
120+
}
115121
MINIO_STORAGE_ENDPOINT = 'minio:9000'
116122
MINIO_STORAGE_ACCESS_KEY = 'KBP6WXGPS387090EZMG8'
117123
MINIO_STORAGE_SECRET_KEY = 'DRjFXylyfMqn2zilAr33xORhaYz5r9e8r37XPz3A'
118124
MINIO_STORAGE_USE_HTTPS = False
119-
MINIO_STORAGE_MEDIA_OBJECT_METADATA = {"Cache-Control": "max-age=1000"}
125+
MINIO_STORAGE_MEDIA_OBJECT_METADATA = {'Cache-Control': 'max-age=1000'}
120126
MINIO_STORAGE_MEDIA_BUCKET_NAME = 'local-media'
121127
MINIO_STORAGE_MEDIA_BACKUP_BUCKET = 'Recycle Bin'
122128
MINIO_STORAGE_MEDIA_BACKUP_FORMAT = '%c/'

tests/django_minio_storage_tests/settings.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@
2929

3030
ALLOWED_HOSTS = []
3131

32-
33-
DEFAULT_STORAGE = "minio_storage.storage.MinioMediaStorage"
34-
STATICFILES_STORAGE = "minio_storage.storage.MinioStaticStorage"
32+
STORAGES = {
33+
"default": {
34+
"BACKEND": "minio_storage.storage.MinioMediaStorage",
35+
},
36+
"staticfiles": {
37+
"BACKEND": "minio_storage.storage.MinioStaticStorage",
38+
},
39+
}
3540

3641
MINIO_STORAGE_ENDPOINT = os.getenv("MINIO_STORAGE_ENDPOINT", "minio:9000")
3742
MINIO_STORAGE_ACCESS_KEY = os.environ["MINIO_STORAGE_ACCESS_KEY"]
@@ -130,8 +135,6 @@
130135

131136
USE_I18N = True
132137

133-
USE_L10N = True
134-
135138
USE_TZ = True
136139

137140

tests/test_app/tests/custom_storage_class_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@deconstructible
2222
class PrivateStorage(MinioStorage):
2323
"""The PrivateStorage MinioStorage subclass can be used directly, as a storage in
24-
settings.DEFAULT_FILE_STORAGE or after instantiated used individually on any django
24+
settings.STORAGES or after instantiated used individually on any django
2525
FileField:
2626
2727
from django.db import models

0 commit comments

Comments
 (0)