Deep Inside Django's ORM: How Django Builds Queries
09-21, 15:00–15:30 (Europe/Lisbon), Auditorium

Django's ORM is probably the most powerful feature of this framework. This talk is about how queries to the database are internally translated into SQL with Query objects and how to hack that process.

In this talk, we will have a deeper look at the fundamentals of Django's ORM.

The first part is about Query objects (django.db.models.sql.query.Query) and how Django uses them to map QuerySets to SQL. In this part, we will also see how Expressions (from django.db.models.expressions) work, how related fields are managed by Django internally, and how aggregate functions are handled.

The second part of the talk provides some creative ways to leverage these insights in real-world projects to customize queries, build dynamic queries and improve performance.


Bas is a software developer for more than 15 years. His first contact with Django was in 2008, even before the 1.0 was released. As a freelance software developer, consultant and tech trainer, he enjoys helping all sorts of tech teams to explore new technologies and get their job done.

He is on Twitter @bascodes and blogs at