Exercise 3: Computing the Threshold in Python vs. Inside SQL — Possible Solution ==================================================================== WHAT THIS CHAPTER DOES ------------------------------ date.today() + timedelta(days=3) runs as ordinary Python code, computed once before the query executes, producing a plain date value that then gets passed into the SQLAlchemy filter as threshold. WHAT FOOD TRACKER (REACT + EXPRESS) DID INSTEAD ------------------------------ That course's own query included date('now', '+3 days') directly inside the SQL string itself - the database computes "three days from today" as part of running the query, rather than that value ever existing as a separate value in the application's own code. WHY BOTH ARE VALID, WITH A REAL DIFFERENCE IN WHERE THE LOGIC LIVES ------------------------------ Neither approach is more correct than the other - both produce the same threshold date. The genuine difference is where the "how many days counts as soon" logic is visible: in this chapter's version, timedelta(days=3) sits directly in the Python route function, readable without needing to also understand SQLite's own date-function syntax. In the Express course's version, that same logic is embedded inside a SQL string, readable only by someone who also understands the SQL dialect's own date arithmetic functions. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly identifies that both approaches produce the same result rather than being different in correctness, and correctly explains the actual difference - where the "how many days" logic is expressed and how easily it's readable, depending on whether it lives in application code or inside a SQL string.