From the course: Advanced Python: Practical Database Examples

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Solution: Develop delete functionality

Solution: Develop delete functionality - Python Tutorial

From the course: Advanced Python: Practical Database Examples

Solution: Develop delete functionality

(lively music) - [Instructor] Let's add delete functionality to this application. We'll start by writing the functionality to delete an individual task. The route for this will be delete/task and then the task-id. Technically, this route could be anything you want but I include the task_id because it'll be useful for the implementation to delete the task from the database. Since we'll be deleting data and not retrieving data, we'll make this a POST method. Since we have the task_id handy, we can query the task table and grab the individual task. We save it in a variable called pending_delete. Then we'll use a session object to delete the task. To save these changes, we'll commit them. With the database operations complete, we'll redirect the user to the individual project page. This'll show all the tasks except the one we just deleted. Now, how do we retrieve the original project ID? You might think we have to feed it in…

Contents