Adam Johnson

Home | Blog | Training | Projects | Colophon | Contact

Recent posts

How to Combine Two Python Decorators

Double combo: human on centaur

Imagine you have some Django views using the same two decorators:


Using Django Check Constraints to Ensure Only One Field Is Set

Spot the odd puppy out

I previously covered using Django’s CheckConstraint class to validate fields with choices and percentage fields that total 100%. Here’s another use case.


Setting Python's Decimal Context for All Threads

Split Threads

Python’s decimal module has concept of a “context.” This defines the default precision of new Decimals, how rounding works, and lots of other behaviour. Maths gets complicated!


CloudFront Updates Are No Longer Soul Destroying

Much less idle cloud gazing

I’ve mentioned CloudFront’s speed, or lack thereof, several times in my past posts.


Use Pathlib in Your Django Settings File

Path through the Sahara

Django’s default settings file has always included a BASE_DIR pseudo-setting. I call it a “pseudo-setting” since it’s not read by Django itself. But it’s useful for configuring path-based settings, it is mentioned in the documentation, and some third party packages use it.


Using Django Check Constraints for the Sum of Percentage Fields

A Simple Database Summation

I previously covered using Django’s CheckConstraint class to ensure a field with choices is constrained to only valid values. Here’s another use case, based on an application I worked on. It uses a check constraint to ensure a set of fields, representing percentages, always sum up to 100.


Detect if Your Tests Are Running on a CI System

Test CI Telescope

If you have some slow tests in your suite, you might want to run them only on CI. To do this, you can detect in your test runner if you’re running on a CI system.


SQL's Implicit Type Conversion

Birds of a feather convert together

At yesterday’s DJUGL meetup I heard a talk from Esau Rodríguez about a buggy new system deployment he survived. His team were deploying a new version of a system that changed the way it connected to its MySQL database, while simultaneously moving session keys from integers to UUID’s. When they discovered the database connection change was flaky, they rolled back to the previous version. This quickly lead to a user reporting being able to see another’s data!


How to Make Django Redirect WWW to Your Bare Domain

The arrows of redirects

If you’re hosting a website on a top level domain, you should set up both the bare domain ( and the “www” subdomain ( People expect to be able to type either version and see your site - no matter which version you advertise.


Use 'python -m pip' Everywhere

Everywhere I tell you! Everywhere!

I’ve just moved all my open source repositories from using plain pip to python -m pip, in test scripts and documentation.