diff --git a/categories/models.py b/categories/models.py index 8bb4d17d..dcd96744 100644 --- a/categories/models.py +++ b/categories/models.py @@ -4,7 +4,6 @@ from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.core.files.images import get_image_dimensions -from django.core.files.storage import get_storage_class from django.db import models from django.urls import reverse from django.utils.encoding import force_str @@ -15,10 +14,19 @@ RELATION_MODELS, RELATIONS, THUMBNAIL_STORAGE, + THUMBNAIL_STORAGE_ALIAS, 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[THUMBNAIL_STORAGE_ALIAS] +except ImportError: + from django.core.files.storage import get_storage_class + + STORAGE = get_storage_class(THUMBNAIL_STORAGE)() class Category(CategoryBase): @@ -28,7 +36,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) diff --git a/categories/settings.py b/categories/settings.py index 6b0db82e..896a265d 100644 --- a/categories/settings.py +++ b/categories/settings.py @@ -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,