Skip to content

Commit

Permalink
simple implementation of Django STORAGES
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Aug 24, 2023
1 parent 56476f9 commit b1da0b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
from django.utils.translation import gettext_lazy as _

from .base import CategoryBase
from . import settings
from .settings import (
RELATION_MODELS,
RELATIONS,
THUMBNAIL_STORAGE,
THUMBNAIL_UPLOAD_PATH,
)

STORAGE = get_storage_class(THUMBNAIL_STORAGE)
# Determine storage method based on Django version
try: # Django 4.2+
from django.core.files.storage import storages
STORAGE = storages[settings.THUMBNAIL_STORAGE_ALIAS]
except ImportError:
from django.core.files.storage import get_storage_class
STORAGE = get_storage_class(settings.THUMBNAIL_STORAGE)()


class Category(CategoryBase):
Expand All @@ -33,7 +39,7 @@ class Category(CategoryBase):
upload_to=THUMBNAIL_UPLOAD_PATH,
null=True,
blank=True,
storage=STORAGE(),
storage=STORAGE,
)
thumbnail_width = models.IntegerField(blank=True, null=True)
thumbnail_height = models.IntegerField(blank=True, null=True)
Expand Down
1 change: 1 addition & 0 deletions categories/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"FK_REGISTRY": {},
"THUMBNAIL_UPLOAD_PATH": "uploads/categories/thumbnails",
"THUMBNAIL_STORAGE": settings.DEFAULT_FILE_STORAGE,
"THUMBNAIL_STORAGE_ALIAS": "default",
"JAVASCRIPT_URL": getattr(settings, "STATIC_URL", settings.MEDIA_URL) + "js/",
"SLUG_TRANSLITERATOR": "",
"REGISTER_ADMIN": True,
Expand Down

0 comments on commit b1da0b8

Please sign in to comment.