As data grows, pages slow down. More often than not, the problem is in the queries rather than the code.
1. Index the right columns
CREATE INDEX idx_order_created
ON shop_order (created_at DESC);2. Avoid the N+1 problem
orders = (Order.objects
.select_related("customer")
.only("id", "total", "customer__name"))3. Load only the fields you need
only() and values() skip unnecessary columns.
4. EXPLAIN ANALYZE
Run a slow query through EXPLAIN ANALYZE to see which step takes the most time.