web | https://adamj.eu/ |
---|---|
Author | Adam Johnson |
Dec. 11, 2023 » Adam Johnson » [Archived Version]
This evening I held a quiz at the December London Django Meetup Group. The quiz is a regular tradition: this was the fifth quiz that I’ve presented, and the sixth overall. Here it is so you can try it at home - answers are at the bottom. Dates refer to …
Read MoreDec. 11, 2023 » Adam Johnson » [Archived Version]
Some models have one or a few large fields that dominate their per-instance size. For example, take a minimal blog post model: from django.db import models class Post(models.Model): blog = models.ForeignKey("Blog", on_delete=models.CASCADE) title = models.TextField() body = models.TextField() body is typically many times larger …
Read MoreDec. 7, 2023 » Adam Johnson » [Archived Version]
Since Django’s inception, the web has gradually moved from HTTP to HTTPS, a welcome move for security. But the history has meant older parts of Django have had a lingering HTTP bias. Many of these have been migrated to default to HTTPS instead in previous versions. Django 5.0 …
Read MoreNov. 9, 2023 » Adam Johnson » [Archived Version]
Here’s a write-up of an optimization I made in my client Silvr’s project. I ended up disabling a PostgreSQL feature called the JIT (Just-In-Time) compiler which was taking a long time for little benefit. This behaviour was observed on PostgreSQL 14, so things may have improved since. Although …
Read MoreOct. 15, 2023 » Adam Johnson » [Archived Version]
I released Boost Your Git DX nearly two weeks ago. It’s the second in my “Boost Your DX” series, following last year’s Boost Your Django DX. Both books aim to improve your development experience with their respective tool. Today I’m happy to announce the bundle deal for …
Read MoreSept. 20, 2023 » Adam Johnson » [Archived Version]
I’ve once more had the pleasure of joining Carlton and Will on the Django Chat podcast, in Episode #146. We spoke on Tuesday, just hours after Django 5.0 alpha 1 was released, on several topics: Favourite features coming in Django 5.0 My new book, Boost Your Git …
Read MoreSept. 14, 2023 » Adam Johnson » [Archived Version]
Django’s template engine has an underappreciated builtins option that selects libraries to preload in every template. Making a library a builtin avoids the need for an explicit {% load %} tag whenever you use its tags or filters. Putting key libraries in builtins can shorten your templates and make development a …
Read MoreAug. 8, 2023 » Adam Johnson » [Archived Version]
Django’s template engine has a string_if_invalid option that replaces missing variable lookups with a string of your choice: TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", # ... "OPTIONS": { # ... "string_if_invalid": "MISSING VARIABLE %s", }, } ] The %s will be replaced with the name of the missing variable. This exists as a debugging aid to …
Read MoreJuly 11, 2023 » Adam Johnson » [Archived Version]
As projects evolve, old functionality gets removed. Often such deletions are incomplete, leaving in their wake unused functions, classes, and other code objects. Unused code is clutter that brings no joy: it hinders comprehension, taxes codebase-wide quality improvements, and can sometimes lead to errors if later used. In an ideal …
Read MoreJuly 3, 2023 » Adam Johnson » [Archived Version]
Sometimes code depends on the order of a QuerySet whilst not specifying an order. This can lead to random, flaky test failures because databases can return rows in any order when none is specified. The problem is made worse by some databases, notably PostgreSQL, which nearly always return rows in …
Read More