Ephes Blog

Miscellaneous things. Not sure what to put here, yet.

Date -

Weeknotes 2023-08-21

, Jochen

We begin in admiration and end by organizing our disappointment. --Gaston Bachelard


Attended a local Django meetup in Cologne and had to learn that the one in Cologne is unfortunately the last active Django meetup in Germany 😢. The topic was django CMS which I knew nothing about, and I was surprised how similar it is to Wagtail which I use a lot.

Added a categories/tags feature (beta) to django-cast, which I postponed because I was afraid that messing with the faceted navigation code in filters.py (based on django-filter) would be hard. It turned out to be as hard as I expected, but now it's done 😅.

On Saturday we went hiking in the Neandertal 🥾, because that's where I live. And we managed to leave it the way you want to find it: as a fascinating puzzle for archaeologists. We did this by throwing a baby carriage (without the baby) into the Düssel (the river that formed the valley).

Articles

Websites

Videos

Books


Using staticfiles with STORAGES in Django 4.2

, Jochen

The other day I was trying to improve a management command of django-cast to make it easier to backup media files like images and videos. There's already an existing command, but it had to assume that you stored your media files on s3 and wanted the backup to be stored on the local filesystem. It would be great if you could configure your production and backup storage and have the backup command work either way. And the new STORAGES setting added in Django 4.2 looks like a perfect fit for this. So I tried using such a configuration:

STORAGES = {
    "default": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "staticfiles": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": "staticfiles",
            "base_url": "/static/",
        },
    },
    "production": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "backup": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": ROOT_DIR.path("backups").path("media"),
        },
    },
}

But it didn't work. It took me longer than I would like to admit to figure out that I should have used this config:

STORAGES = {
    "default": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
    "production": {"BACKEND": "config.settings.local.CustomS3Boto3Storage"},
    "backup": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
        "OPTIONS": {
            "location": ROOT_DIR.path("backups").path("media"),
        },
    },
}

If you want to replace django.contrib.staticfiles.storage.StaticFilesStorage with whitenoise for production, it's sufficient overwrite the backend in the production settings like this:

STORAGES["staticfiles"]["BACKEND"] = "whitenoise.storage.CompressedManifestStaticFilesStorage"