Storage 4.2: how to subclass default

Yes, thank you for replying leandrodesouzadev. It was also my way to do it before 4.2 and the STORAGES settings.

In documentation it says “A dictionary containing the settings for all storages to be used with Django.” which I emphasis as we shouldn’t have to create PrivateMediaStorage or PublicMediaStorage classes somewhere else. The idea, as far as I understand, is to get all storages in one place (in the settings, which sound very good).

Moreover, I think prefixed AWS_… settings should be avoided if possible. It’s better because there are plenty of other S3 providers nowadays and the naming could be confusing. This makes the STORAGES settings pretty good to me.

But I really don’t like not being DRY and I can’t see another way to do it than the solution I posted, which doesn’t look very good to me right now. But I don’t see how to do it differently…

I imaginated, instead of making new class, would be to reference a previously defined storage in the BACKEND option.

Example:

DEFAULT_S3_STORAGE_OPTIONS = {
    
}
STORAGES = {
    "default": {
        "BACKEND": "storages.backends.s3.S3Storage",
        "OPTIONS": {
            "access_key": env.str("OVH_ACCESS_KEY"),
            "secret_key": env.str("OVH_SECRET_KEY"),
            "bucket_name": env.str("BUCKET_NAME"),
            "region_name": env.str("BUCKET_REGION"),
            "endpoint_url": "https://s3.gra.io.cloud.ovh.net",
            "custom_domain": f"{env.str('BUCKET_NAME')}.s3.gra.io.cloud.ovh.net",
        },
    },
    "public_media": {
        "BACKEND": "default",  # reuse previously defined default with same options
        "OPTIONS": {
            # add or override options defined in default
            "location": "media",
            "default_acl": "public-read",
            "file_overwrite": True,
            "querystring_auth": False,
        },
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}

Do you think it would make sense ?
Or do you have some other idea ?