Troubleshooting n+1 problems with Django ORM

This is a simplified test case for an ongoing problem in a bigger project.