Skip to content

Commit 257d93b

Browse files
authored
Update README.md
1 parent cb2432a commit 257d93b

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ INSTALLED_APPS = [
2828
'smart_storages',
2929
]
3030
```
31+
## Example: Custom Storage Classes
32+
33+
Define specialized storage classes in your code (e.g., `views.py` or a separate `storages.py`):
34+
35+
```python
36+
# views.py (or storages.py)
37+
38+
from smart_storages import BaseSpecialS3Storage
39+
40+
class ImportExportS3Storage(BaseSpecialS3Storage):
41+
storage_key = "import_export"
42+
43+
class AnalyticsS3Storage(BaseSpecialS3Storage):
44+
storage_key = "analytics"
45+
```
46+
3147

3248
## Example: Configuring Multiple Storages
3349

@@ -37,8 +53,6 @@ Add your bucket names and the STORAGES setting:
3753
# settings.py
3854

3955
AWS_STORAGE_BUCKET_NAME = "main-bucket"
40-
COURSE_IMPORT_EXPORT_BUCKET = "import-export-bucket"
41-
ANALYTICS_BUCKET = "analytics-bucket"
4256

4357
STORAGES = {
4458
# Default file storage
@@ -51,7 +65,7 @@ STORAGES = {
5165
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
5266
},
5367

54-
# Import/export-specific S3 storage (using your custom base class)
68+
# Import-export-specific S3 storage (using your custom base class)
5569
"import_export": {
5670
"BACKEND": "special_storages.s3.ImportExportS3Storage",
5771
"OPTIONS": {
@@ -70,21 +84,17 @@ STORAGES = {
7084
}
7185
```
7286

73-
## Example: Custom Storage Classes
87+
## Example: Usage
7488

75-
Define specialized storage classes in your code (e.g., `views.py` or a separate `storages.py`):
89+
```
90+
# it will save the image in given bucket.
91+
class PublicImage(models.Model):
92+
file = models.FileField(storage=ImportExportS3())
7693
77-
```python
78-
# views.py (or storages.py)
7994
80-
from special_storages.base import BaseSpecialS3Storage
95+
```
8196

82-
class ImportExportS3Storage(BaseSpecialS3Storage):
83-
setting_name = "COURSE_IMPORT_EXPORT_BUCKET"
8497

85-
class AnalyticsS3Storage(BaseSpecialS3Storage):
86-
setting_name = "ANALYTICS_BUCKET"
87-
```
8898

8999
> **Note:**
90100
> You can place these custom storage classes in any appropriate module (such as `storages.py`), and reference them in your `STORAGES` Django setting.

0 commit comments

Comments
 (0)