Simon Willison: TILs on django

Atom feed for django

django Building a blog in Django - 2023-08-15

We launched the Datasette Cloud blog today. The Datasette Cloud site itself is a Django app - it uses Django and PostgreSQL to manage accounts, teams and soon billing and payments, then launches dedicated containers running Datasette for each customer. …

django Adding a Datasette ASGI app to Django - 2022-10-20

Datasette is implemented as an ASGI application. …

django Using just with Django - 2022-06-06

Jeff Triplett convinced me to take a look at just as a command automation tool - sort of an alternative to Make, except with a focus on commands rather than managing build dependencies. …

django Django data migration using a PostgreSQL CTE - 2021-05-17

I figured out how to use a PostgreSQL CTE as part of an update statement in a Django data migration. The trick here is mainly understanding how to combine CTEs with a PostgreSQL update - here's the pattern for that: …

django Enabling a gin index for faster LIKE queries - 2021-05-16

I tried using a gin index to speed up LIKE '%term%' queries against a column. …

django migrations.RunSQL.noop for reversible SQL migrations - 2021-05-02

migrations.RunSQL.noop provides an easy way to create "reversible" Django SQL migrations, where the reverse operation does nothing (but keeps it possible to reverse back to a previous migration state without being blocked by an irreversible migration). …

django Django Admin action for exporting selected rows as CSV - 2021-04-25

I wanted to add an action option to the Django Admin for exporting the currently selected set of rows (or every row in the table) as a CSV file. …

django Filter by comma-separated values in the Django admin - 2021-04-21

I have a text column which contains comma-separated values - inherited from an older database schema. …

django Usable horizontal scrollbars in the Django admin for mouse users - 2021-04-20

I got a complaint from a Windows-with-mouse user of a Django admin project I'm working on: they couldn't see the right hand columns in a table without scrolling horizontally, but since the horizontal scrollbar was only available at the bottom of the page they had to scroll all the way to the bottom first in order to scroll sideways. …

django Enabling the fuzzystrmatch extension in PostgreSQL with a Django migration - 2021-04-18

The PostgreSQL fuzzystrmatch extension enables several functions for fuzzy string matching: soundex(), difference(), levenshtein(), levenshtein_less_equal(), metaphone(), dmetaphone() and dmetaphone_alt(). …

django Efficient bulk deletions in Django - 2021-04-09

I needed to bulk-delete a large number of objects today. Django deletions are relatively inefficient by default, because Django implements its own version of cascading deletions and fires signals for each deleted object. …

django How to almost get facet counts in the Django admin - 2021-03-11

For a tantalizing moment today I thought I'd found a recipe for adding facet counts to the Django admin. …

django Pretty-printing all read-only JSON in the Django admin - 2021-03-07

I have a bunch of models with JSON fields that are marked as read-only in the Django admin - usually because they're recording the raw JSON that was imported from an API somewhere to create an object, for debugging purposes. …

django Show the timezone for datetimes in the Django admin - 2021-03-02

Django supports storing dates in a database as UTC but displaying them in some other timezone - which is good. But... by default datetimes are shown in the Django admin interface without any clue as to what timezone they are being displayed in. …

django Writing tests for the Django admin with pytest-django - 2021-03-02

I'm using pytest-django on a project and I wanted to write a test for a Django admin create form submission. Here's the pattern I came up with: …

django Adding extra read-only information to a Django admin change page - 2021-02-25

I figured out this pattern today for adding templated extra blocks of information to the Django admin change page for an object. …

django PostgreSQL full-text search in the Django Admin - 2020-07-25

Django 3.1 introduces PostgreSQL search_type="websearch" - which gives you search with advanced operators like "phrase search" -excluding. James Turk wrote about this here, and it's also in my weeknotes. …