Recent

2025-12-08

▩︎ Django spotlight: humanize template filters

I frequently consult the docs of Django's set of default template tags and filters and there's one part I often forget about, because it's not enabled by default: django.contrib.humanize. Here's a reminder.

Continue reading »

2025-12-04

2025-12-02

▩︎ Customizing the HTML name of a Django form field

Django uses the name of the form field as the name attribute of the corresponding form element in HTML. If you ever need to change it, here's how (Django 5.2+).

Continue reading »

2025-11-28

▩︎ A first look at Django's new background tasks

Django 6.0 introduces a built-in background tasks framework in django.tasks. But don't expect to phase out Celery, Huey or other preferred solutions just yet.

Continue reading »

2025-11-26

2025-11-24

▩︎ Django spotlight: SimpleLazyObject & Co.

We probably all know the ins and outs of Django models, and the settings we need to tweak before heading to production. But Django's packed with tiny bits of useful, lesser known constructs and functionality you can safely reuse. Like SimpleLazyObject.

Continue reading »

2025-11-13

2025-11-12

2025-11-05

▩︎ Ping me: using ntfy to stay updated

I'm often finding myself being afk for a few minutes, while some process is running. Got to stretch those legs, you know?

I've started using nfty to send me a notification on my phone as soon as a process has completed, so I can actually go ahead and step away without having to check in. And it really couldn't be easier.

First: set up your ntfy account and a topic.

Second: add something like the function below to your .{bash,zsh}rc. Or turn it into a script.

function ping_me () {
    local default="FYI: that thing you triggered just stopped."
    local message="${1:-$default}"
    # $ntfy_topic_url is something like 
    # https://ntfy.sh/yoursecretishtopicname
    curl -sf \
        -H "Title: laptop" \
        -d "${message}" \
        ${ntfy_topic_url} \
        > /dev/null || echo "Ping failed"
}

Third: use it!

Now running just docker-build docker-push && ping_me means Docker can have some fun while I go grab a coffee, check on the laundry, or walk around aimlessly trying to figure out what I was planning on doing.

2025-11-03

▩︎ Introducing Rootcause

Something that always made me wonder: why doesn't the IntegrityError raised by a database (driver) include some actual actionable data?

I don't know. I do know that it doesn't have to stay that way! With Rootcause you'll be able to gather all necessary information when you violate the most common types of constraints in Django.

import rootcause

try:
    ... # something violates a constraint
except IntegrityError as e:
    cause = rootcause.resolve(e, model=MyModel)
    if cause.is_check(name="max_amount"):
        raise MaxAmountExceeded()
    if cause.is_unique(name="payment_reference"):
        raise AlreadyPaid()

The goal of Rootcause is twofold: provide more information and eliminate differences between databases.

Rootcause has been tested with recent versions of SQLite, PostgreSQL and MySQL, and requires Django 5.1 or better.

Go check it out over on GitHub and fetch it from PyPI.

💡︎ Streaming radio

One of the extremely useful snippets I discovered in Evan Hahn's Scripts I wrote that I use all the time is radio.

I cannot work in silence. I need to have something going in the background, preferably classics and not encumbered with too much chit-chat.

Instead of having a browser tab or app sitting there in the background, I adapted Evan's script. It uses mpv, so now I've got a Ghostty tab running in the background instead.

#!/usr/bin/env bash
# Check https://mytuner-radio.com/nl/radio/vrt-radio-2-limburg-402485/
set -e
set -u
set -o pipefail

if [ "$1" == joeeasy ]; then
  url='https://icecast-qmusicbe-cdp.triple-it.nl/joe_easy.aac'
elif [ "$1" == radio2 ]; then
  url='http://vrt.streamabc.net/vrt-radio2limburg-mp3-128-2845863?sABC=68s94r20#0#r7p08610r6n19o27sn00016q8n8877qs#&aw_0_1st.playerid=&amsparams=playerid:;skey:1761168928'
else
  echo "don't know $1" 1>&2
  exit 1
fi

exec mpv --really-quiet "$url"

2025-11-02

2025-11-01