137 Posts Tagged ‘django’

(All tags.)


Django: Avoid database queries in template context processors

Time for a little game of moving templating pieces around…

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:

Read more...

Django: Parametrized tests for all model admin classes

I’ve got a lovely bunch of parametrized tests, there they are a-standing in a row…

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.

Read more...

Django: How to profile and improve startup time

A waterfall, as used several times in this post.

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.

Read more...

How to migrate from Django’s PostgreSQL CI Fields to use a case-insensitive collation

This migration is a little bit fiddly...

If you upgrade to Django 4.2, you may see system check warnings like:

Read more...

django-upgrade release with Django 4.2 fixers

Squid-shing away your toil.

I just released django-upgrade 1.13.0. The headline features are some new fixers targetting Django 4.2, which is currently in alpha.

Read more...

Django Settings Patterns to Avoid

Settings are the engine of your project.

Here are some potential mistakes made with Django settings that you can avoid.

Read more...

Django-related Deals for Black Friday and Cyber Monday 2022

Discounts, discounts, read all about them!

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.

Read more...

unittest’s new context methods in Python 3.11 (with backports)

A testing concerto

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.

Read more...

django-upgrade Mega Release 1.11.0

Some busy bees have contributed their fixes.

I just released version 1.11.0 of django-upgrade, a tool for automatically upgrading your Django project code. This release contains a lot of new features and fixes, thanks to new contributors including those at the Djangocon Europe sprints. Let’s look at the top changes.

Read more...

Migrate PostgreSQL IDs from serial to identity after upgrading to Django 4.1

Let me regale you with the ballad of the serial to identity column migration…

The Django 4.1 release notes feature this short, innocent-looking note:

Read more...