Djangocon EU: advanced ORM kung-fu - Mathias Wedeken

Tags: django, djangocon

(One of my summaries of the 2026 Djangocon EU in Athens).

Full title: advanced ORM kung-fu for on-demand filtering, sorting, and summing 40 million financial transactions.

He’s working on a property management platform (so: buildings, rent payments, extra costs, maintenance, grouping per housing complex, etc). 300000 users. 472000 financial accounts. 40 million transactions.

Users expect real-time filtering, sorting and summing. But originally his website often had “please wait for 10 seconds” spinners. This should be improved.

A colleague told him that the database ought to be able to handle everything just fine. So the goal was to fully leverage postgresql through Django’s ORM without writing raw SQL.

Some things he discovered:

  • Annotations are composable. Almost functional programming.

  • Func(template=...) to drop custom SQL expressions into the ORM. You can use them to group items in a custom way, for instance.

  • In JSONB, you can use __0 to grab the first element of a list. Use that before using raw SQL.

  • Materialized views (note: use “managed=False”) means you have pre-computed data available, usable just like a model. You do have to handle those views (create, refresh) yourself, though.

  • Coalesce is something he mentioned and it looked useful, but I have to check what it actually does. The slides had a bit too much content to see what was happening.

https://reinout.vanrees.org/images/2026/moezel8.jpeg

Unrelated photo explanation: a trip in November to the Mosel+Eifel region in Germany. View on Virneburg from the town’s similarly-named castle.