web | https://adamj.eu/ |
---|---|
Author | Adam Johnson |
March 23, 2023 » Adam Johnson » [Archived Version]
Django’s template engine allows you to augment template contexts with context processors. These are functions that take the current request and return a dictionary to be merged into the context: from example.models import HotDog from example.models import HotDogState def hot_dog_stats(request): return { "hot_dogs_eaten": HotDog.objects.filter( state …
Read MoreMarch 17, 2023 » Adam Johnson » [Archived Version]
Here’s an application of “test smarter, not harder”, as per Luke Plant’s post. I came up with this recently whilst working on my client Silvr’s project, and I’m pretty proud of it. It should apply to any project using Django’s admin. When you declare a …
Read MoreMarch 2, 2023 » Adam Johnson » [Archived Version]
Your Django project’s startup time impacts how smooth it is to work with. Django has to restart your project every time you run a management command and when runserver reloads. This involves importing all your apps, and thus all the modules that they import. As you add more code …
Read MoreFeb. 23, 2023 » Adam Johnson » [Archived Version]
If you upgrade to Django 4.2, you may see system check warnings like: example.User.email: (fields.W906) django.contrib.postgres.fields.CIEmailField is deprecated. Support for it (except in historical migrations) will be removed in Django 5.1. HINT: Use EmailField(db_collation="…") with a case-insensitive non-deterministic collation instead …
Read MoreFeb. 17, 2023 » Adam Johnson » [Archived Version]
I just released django-upgrade 1.13.0. The headline features are some new fixers targetting Django 4.2, which is currently in alpha. Let’s walk through these new fixers. For more detail on any of them, see the Django 4.2 README section. New headers argument in tests Recent-ish …
Read MoreNov. 24, 2022 » Adam Johnson » [Archived Version]
This post is an adapted extract from my book Boost Your Django DX, available now. Here are some potential mistakes made with Django settings that you can avoid. Don’t Read Settings at Import Time Python doesn’t make a distinction between import time and run time. As such, it …
Read MoreNov. 24, 2022 » Adam Johnson » [Archived Version]
This post is an adapted extract from my book Boost Your Django DX, available now. Here are some potential mistakes made with Django settings that you can avoid. Don’t Read Settings at Import Time Python doesn’t make a distinction between import time and run time. As such, it …
Read MoreNov. 21, 2022 » Adam Johnson » [Archived Version]
Here are some Django-related deals for this year’s Black Friday (25th Nov) and Cyber Monday (28th Nov), including my own. For more deals on general Python-related products, see Trey Hunner’s post. My books My two books, Boost Your Django DX and Speed Up Your Django Tests, have 50 …
Read MoreNov. 21, 2022 » Adam Johnson » [Archived Version]
Here are some Django-related deals for this year’s Black Friday (25th Nov) and Cyber Monday (28th Nov), including my own. For more deals on general Python-related products, see Trey Hunner’s post. My books My two books, Boost Your Django DX and Speed Up Your Django Tests, have 50 …
Read MoreNov. 14, 2022 » Adam Johnson » [Archived Version]
Python 3.11 only made one change to unittest, but it’s a good one: context manager methods. These methods can simplify setup and teardown logic in many cases, such as dynamic use of unittest.mock. In this post we’ll look at a couple fo examples using the new …
Read More