How many database queries does this run?
books = Book.objects.filter(year__gte=2020)books = books.exclude(title="")books = books.order_by("title")What this Django test measures, in short
This test checks whether you can predict what Django does behind the scenes: when a QuerySet actually hits the database and how many times, how model fields and relations behave, how URLs resolve, how templates escape and handle missing values, and how forms and CSRF protection work.
Questions assume Django 5 with default settings. Django REST Framework isn't covered. The questions are our own and not standardised, so treat the result as a knowledge check, not a certification.
By What's Your IQ · Reviewed 4 Oct 2026- Format
- 15 questions on what Django does, 4 options each
- Topics
- Models, QuerySets, views and URLs, templates, forms and security
- Assumes
- Comfortable Python and basic SQL
- Framework
- Created at a Kansas newspaper; open-sourced 2005
Count the queries
Following a foreign key on each row triggers a fresh query per row, the N+1 problem. Pick a strategy and a page size, and see what actually reaches the database.
books = Book.objects.all()for b in books: print(b.author.name)
Correct in tests, wrong under load
for a in Author.objects.all(): n = a.book_set.count() print(a.name, n)
authors = Author.objects.annotate( n=Count("book"))for a in authors: print(a.name, a.n)Counting per row inside a loop is N+1 again. annotate(Count()) gets every count in one GROUP BY query.
- Django Software Foundation. FAQ: General. docs.djangoproject.com.
- Django Software Foundation. Download and supported versions; release notes. djangoproject.com.