Django Time-Based Lookups: A Performance Trap

Django&rsquo;s field lookups are one of the ORM&rsquo;s best features, but time-based lookups can quietly bypass database indexes, turning fast queries into expensive full table scans. A Slow Production Query I ran into this while debugging a 30 second query on a large table (~25 million rows): class Event (models . Model): timestamp = models . DateTimeField(db_index = True ) Event . objects .…